1. 程式人生 > >cordova環境配置(android)

cordova環境配置(android)

tps process nsa epo lan 找到 網上 adl 下載

  1. 打開命令行安裝全局cordova npm install -g cordova (這裏不要使用cnpm,會導致安裝不全,有很多坑)
  2. 創建項目 create hello
  3. cd hello
  4. 安裝java開發工具包(JDK)Android SDK
  5. 設置環境變量 系統變量->新建 紅色字體為自己的路徑

變量名:JAVA_HOME

變量值:D:\Program Files\Java\jdk1.8.0_73?

變量名:SDK_HOME

變量值:F:\BaiduYunDownload\adt-bundle-windows-x86_64-20140702\sdk

變量名:path

變量值:

D:\Program Files

\Java\jdk1.8.0_73\bin;F:\BaiduYunDownload\adt-bundle-windows-x86_64-20140702\sdk\tools;F:\BaiduYunDownload\adt-bundle-windows-x86_64-20140702\sdk\platform-tools(註意分號)

變量名:classpath

變量值:

D:\Program Files\Java\jdk1.8.0_73\lib;D:\Program Files\Java\jdk1.8.0_73\lib\tools.jar;D:\Program Files\Java\jdk1.8.0_73\lib\dt.jar(註意分號)

6.報錯:缺少platform 26

7.從android-sdk-windows.7z中的SDK Manager.exe中下載最新的android 8.0.0(API 26)

8.技術分享

9.android update sdk --no-ui --all --filter "extra-android-m2repository" (沒用)

10.下載gradle-4.2-all.zip解壓,在環境變量配置PATH PATH=C:\Program Files\gradle-x.x\bin

11.hello(項目)>platforms>android>cordova>lib>builders>GradleBuilder.js

下面找到

var distributionUrl = process.env[‘CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL‘] || ‘https\\://services.gradle.org/distributions/gradle-3.3-all.zip‘;

改成:

var distributionUrl = process.env[‘CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL‘] || ‘file:///D:/work/gradle-3.3-all.zip‘;

根據版本先從網上下載下來,在本地加載

  1. index.html中的

<meta http-equiv="Content-Security-Policy" content="default-src ‘self‘ data: gap: https://ssl.gstatic.com ‘unsafe-eval‘; style-src ‘self‘ ‘unsafe-inline‘; media-src *; img-src ‘self‘ data: content:;">

刪除或改成:

<meta http-equiv="Content-Security-Policy">

不然js無法加載成功

  1. 調用插件----攝像頭

cordova plugin add cordova-plugin-camera

html<button onClick="takePhoto()">拍照</button>

<img id="m1">

js

function takePhoto() {

navigator.camera.getPicture(takeSuccess, takeFail, {

destinationType : Camera.DestinationType.FILE_URI

});

//拍照成功後回調

function takeSuccess(imageURI) {

console.log(‘success‘ + imageURI);

document.getElementById(‘m1‘).src=imageURI;

}

//失敗後回調

function takeFail(message) {

navigator.notification.alert("拍照失敗,原因:" + message);

}

}

  1. 調用插件----在瀏覽器中打開網頁

cordova plugin add cordova-plugin-inappbrowser

<button onclick="cordova.InAppBrowser.open(‘http://www.baidu.com‘, ‘_blank‘, ‘location=yes‘)"> Test InAppBrowser </button>

15.自定義插件開發

http://m.blog.csdn.net/qq_23179075/article/details/77104276

cordova環境配置(android)