Cordova packaged WebApp and turn the camera permission

1.Node.js installation

After installation open the console, enter  the Node -v  , displays the current version number, the installation was successful

2.Cordova installation

cordova use npm installation, input  npm install -g cordova  performs the latter

3.Java JDK installation

Now jdk versions are automatically written to environment variables directly installing ok. Console input java -version versioning information, that the installation was successful. Enter javac appear helpful information, that is, the configuration is successful.

If it does not succeed configuration, manual configuration is also quite simple.

New JAVA_HOME environment variable, the variable is stored path jdk

13516692-3ce550ef5d55cf18.png

System variables Path which joined jdk bin directory % JAVA_HOME% \ bin; Note the semicolon

System Variables CLASSPATH starting position inside the variable value is added ;.% JAVA_HOME% \ lib;

Save when you enter javac test whether the configuration.

I'm here because webassembly kit installed, java and python environment variables point to a fixed version in webassembly directory.
We need to change the path to the new directory helpless, when using webassembly project and then switch back.

4. New Cordova app application
in the terminal input
cordova create vending org.shahho.vend vendqq

Creating a vending applications, vending folder name, org.shahho.beats.vending package name, vending1 application name

5. Enter the vending folder name
cd vending

select 6.Cordova add android platform installation version

cordova platform add [email protected] --save
If you have the wrong version or versions of pollution, can
platform android cordova rm
to delete the current Android version, and then enter
cordova platform add [email protected] --save
choose the correct version
can be used
cordova platform ls
view the platform packaged version

7. packaged and released APK
cordova Build
or
cordova build Android
using the command
cordova prepare
generates an Android studio project file. Android studio package needs to determine Gradle version are the same.
Learn more about: Android Studio in Gradle versions and updates

8. Use Crosswalk
the X-: npm install -g [email protected] // specify cordova version installed
(not like my solution is to vending - plugins --cordova- plugin-crosswalk-webview - hooks context.requireCordovaModule and which uses a given place, require change, and require installation need to be introduced q, elementtree other modules in the vending local directory)

Plug-in installed crosswalk before packaged and released cordova build

cordova plugin add cordova-plugin-crosswalk-webview

9. You can also install other plug-ins, such as
cordova camera API provided with the device camera to interact.
cordova plugin add cordova-plugin-camera

Through the camera API, we can access the photo library or shoot photos, url file path returned base64 encoded string picture or picture.

10.manifest.xml disposed
in vending / platforms / android / app / src / AndroidManifest.xml was added, allowing file access apk hardware corresponding
<uses-feature android: name = "android.hardware.camera" />

  <uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


11. Install multiple versions of android sdk

13516692-85bfd279fe01c42c.png

打开andriod studio,进入 settings - Appearance & Behavior - System Settings - Android SDK

12.在cordova中切换android sdk版本
     a. cordova platform rm android
     b. cordova platform add [email protected]


13516692-5681257096b840be.png

crosswalk打包apk
cordova build --release android --minSdkVersion=27

13.如果crosswalk安装报错:
Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
需要找到项目根目录 - plugins - cordova-plugin-crosswalk-webview - hooks文件夹下面的js
将对应的
var deferral = context.requireCordovaModule('q').defer()
修改为
var deferral = require('q').defer(),
...
如果q模块不存在,需要安装一下

npm install q -s

14.如果发布released版本,用于apk签名
cordova build --release android --minSdkVersion=28
minSdkVersion=28表示对应的sdk版本 28=8.0.0  , 27=7.1.0,  26=7.0.0 ...

15.对app-release-unsigned.apk进行签名:
我的"jdk1.8.0_211"目录是C:\Program Files\Java\jdk1.8.0_211
debug.keystore所在的目录是C:\Users\QQ VIP2\.android\debug.keystore
1.首先进入"jdk1.8.0_211\bin"目录(keytool.exx在这个目录下)
cd "Program Files\Java\jdk1.8.0_211\bin"
(如果某一层级文件夹名称有空格,需要用引号包围整个路径)
2.运行keytool.exe
使用.\>keytool -genkeypair -alias xdad.keystore -keyalg RSA -validity 4000 -keystore xdad.keystore

生成一个xdad.keystore的签名文件

16.使用命令完成apk的打包签名:
cordova run android --release -- --keystore=xdad.keystore --storePassword=android --alias=xdad.keystore --password=android
xdad.keystore文件放在vending目录下(cordova命令也是运行在vending目录下)

17.如果crosswalk错误为:xwalk_core_library.aar dimens_03.xml resource not found
可能是android支持库不兼容造成的,可以在platforms -- android -- app -- build.gradle文件里面强制构建使用较低的支持库
configurations.all {

    resolutionStrategy {

        force 'com.android.support:support-v4:27.1.0'

    }

}
注意是app文件夹里面的build.gradle,不是其他目录的。

18.加入plagins如crosswalk打包apk,好像生成的是-released-unsigned版本:

cordova run android --release --minSdkVersion = 27 --keystore = xdad.keystore --storePassword = android --alias = xdad.keystore --password = android
in one run
cordova run android --release - --keystore = xdad.keystore --storePassword = android --alias = xdad.keystore --password = android
generated signature version

Reproduced in: https: //www.jianshu.com/p/6fae7eccdc86

Guess you like

Origin blog.csdn.net/weixin_34220623/article/details/91320632