Deploy to mobile phones and use of cordova plugins
We've developed a simple web application, and now we're going to do some preparations before deploying it to mobile. Ionic supports two platforms: ios and android, the default Ionic project does not add these two platforms, we need to add it manually, cd to the development directory to execute the command:
I only need the Android platform here, and after executing it, I will execute the command to view the list of platforms you have added:
> cordova platform ls
You have been opted out of telemetry. To change this, run: cordova telemetry on. Installed platforms: android 7.0.0 Available platforms: browser ~5.0.1 ios ~4.5.4 osx ~4.0.1 windows ~5.0.0 www ^3.12.0
Android package
(If there is a problem with this command, you can remove -release and then debug compilation, and the compilation is completed, DOS will display the apk directory location)
If your smart eyes spot the following words: Build Success! It means that you have successfully packaged. Be patient, the end of the command line will prompt you where the apk is generated.
When I execute the packaging command again, the error will be as follows, the error is that the jdk version is too high, I am the "jdk-10.0.1" version, and I can re-download and install a "1.8.0_171" version to solve the problem!!
C:\project\android\myApp>ionic cordova build android --release Running app-scripts build: --platform android --target cordova [17:06:47] build dev started ... [17:06:47] clean started ... [17:06:47] clean finished in 8 ms [17:06:47] copy started ... [17:06:47] deeplinks started ... [17:06:47] deeplinks finished in 15 ms [17:06:47] transpile started ... [17:06:50] transpile finished in 3.71 s [17:06:50] preprocess started ... [17:06:50] preprocess finished in 1 ms [17:06:50] webpack started ... [17:06:51] copy finished in 3.96 s [17:06:56] webpack finished in 5.58 s [17:06:56] sass started ... Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning. [17:06:58] sass finished in 2.05 s [17:06:58] postprocess started ... [17:06:58] postprocess finished in 10 ms [17:06:58] lint started ... [17:06:58] build dev finished in 11.65 s > cordova build android --release
You have been opted out of telemetry. To change this, run: cordova telemetry on. Android Studio project detected
ANDROID_HOME=C:\Users\itsvse_pc\AppData\Local\Android\sdk JAVA_HOME=C:\Program Files\Java\jdk-10.0.1 (node:14940) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Requirements check failed for JDK 1.8 or greater (node:14940) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[17:07:01] lint finished in 3.00 s Execute the above command again, because my network speed is slow, and it is the first time to execute, download a lot of components, etc., and execute it for 12 minutes, as shown in the figure below:
C:\project\android\myApp\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk 是编译后的app存放地址。
I copy "app-release-unsigned.apk" to my phone (Huawei Honor 10), and the error will be as follows:
This is due to the app not being signed and not being able to install.
apk signature
Since my Java directory is in the environment variables, I only need to execute the cmd command as follows:
/*说明:-genkey 产生密钥 -alias demo.keystore alias demo.keystore -keyalg RSA uses the RSA algorithm to encrypt signatures -validity 40000 Validity 4000 days -keystore itsvse.keystore filename */ apksigner is located in the build-tools directory of the SDK directory. It must be noted that the v2 signing method was only introduced after Android 7.0, so apksigner.jar can only be found in the SDK\build-tools\ for version >25. Open cmd, cut the directory to SDK\build-tools\Version number\lib (for example, C:\Users\itsvse_pc\AppData\Local\Android\Sdk\build-tools\28.0.0\lib), and execute:
Example:
D:\>jarsigner -verbose -keystore demo.keystore -signedjar demo_signed.apk demo.apk demo.keystore
/*说明:-verbose 输出签名的详细信息 -keystore demo.keystore keystore location -signedjar demor_signed.apk demo.apk demo.keystore officially signed, the file demo_signed generated after signing in order in the three parameters, the file demo.apk to be signed, and the keystore demo.keystore.*/
Check if the apk is already signed:
We copy the signed "output.apk" file to the phone, and then install it, it can be installed normally, and it can run normally, as shown in the figure below:
|