参照以下链接:
https://blog.csdn.net/qq_20264891/article/details/79319408
当 cordova 项目安装的 android 平台版本 与 系统安装的 Android SDK 版本不一致时,打包失败!!!
解决方案:
增加显示、删除、添加 android 库的命令:
显示cordova当前已添加的平台及版本:
ionic cordova platform ls
F:GitCodemyApp>ionic cordova platform ls > cordova platform ls Installed platforms: android 6.0.0 Available platforms: browser ~5.0.1 ios ~4.5.4 osx ~4.0.1 windows ~6.0.0
删除当前平台
ionic cordova platform rm android
F:GitCodemyApp>ionic cordova platform rm android > cordova platform remove android --save Removing platform android from config.xml file... Removing android from cordova.platforms array in package.json
添加android平台最新版(安装的android@7.1.1,对应的Android SDK android-27)
ionic cordova platform add android
F:GitCodemyApp>ionic cordova platform add android > cordova platform add android --save Using cordova-fetch for cordova-android@~7.1.1 Adding android project... Creating Cordova project for the Android platform: Path: platformsandroid Package: io.ionic.starter Name: myApp Activity: MainActivity Android target: android-27 Android project created with cordova-android@7.1.1 Android Studio project detected Android Studio project detected Installing "cordova-plugin-device" for android Installing "cordova-plugin-ionic-keyboard" for android Installing "cordova-plugin-ionic-webview" for android Subproject Path: CordovaLib Subproject Path: app Installing "cordova-plugin-splashscreen" for android Installing "cordova-plugin-statusbar" for android Installing "cordova-plugin-whitelist" for android This plugin is only applicable for versions of cordova-android g eater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. --save flag or autosave detected Saving android@~7.1.1 into config.xml file ...
添加android平台指定新版(安装的android@6.0.0,对应的Android SDK android-24,当前系统已经安装了对应版本的Android SDK,会执行对应的编译操作)
ionic cordova platform add android@6.0.0
F:GitCodemyApp>ionic cordova platform add android@6.0.0 > cordova platform add android@6.0.0 --save Using cordova-fetch for cordova-android@6.0.0 Adding android project... Creating Cordova project for the Android platform: Path: platformsandroid Package: io.ionic.starter Name: myApp Activity: MainActivity Android target: android-24 Subproject Path: CordovaLib Android project created with cordova-android@6.0.0 Installing "cordova-plugin-device" for android ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean BUILD SUCCESSFUL Total time: 2.923 secs Installing "cordova-plugin-ionic-keyboard" for android ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean BUILD SUCCESSFUL Total time: 3.168 secs Installing "cordova-plugin-ionic-webview" for android Plugin doesn't support this project's cordova-android version. cordova-android: 6.0.0, failed version requirement: >=6.4.0 Skipping 'cordova-plugin-ionic-webview' for android Installing "cordova-plugin-splashscreen" for android ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean BUILD SUCCESSFUL Total time: 3.04 secs Installing "cordova-plugin-statusbar" for android ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean BUILD SUCCESSFUL Total time: 2.837 secs Installing "cordova-plugin-whitelist" for android ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :clean :CordovaLib:clean BUILD SUCCESSFUL Total time: 2.666 secs This plugin is only applicable for versions of cordova-android gr eater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. --save flag or autosave detected Saving android@~6.0.0 into config.xml file ...
最后打包安卓apk:(未签名版本编译成功的效果)
ionic cordova build android --release
F:GitCodemyApp>ionic cordova build android --release > ng run app:ionic-cordova-build --platform=android Date: 2018-10-23T08:40:55.031Z Hash: bf05a92055d1e7f9f1aa Time: 26064ms chunk {common} common.js, common.js.map (common) 15 kB [rendered] chunk {87} 87.js, 87.js.map () 36.2 kB [rendered] chunk {cordova} cordova.js, cordova.js.map (cordova) 72.8 kB [rendered] chunk {0} 0.js, 0.js.map () 18.6 kB [rendered] chunk {1} 1.js, 1.js.map () 1.9 kB [rendered] chunk {2} 2.js, 2.js.map () 6.13 kB [rendered] chunk {3} 3.js, 3.js.map () 1.08 kB [rendered] chunk {4} 4.js, 4.js.map () 95.6 kB [rendered] chunk {5} 5.js, 5.js.map () 3.26 kB [rendered] chunk {6} 6.js, 6.js.map () 28.6 kB [rendered] chunk {7} 7.js, 7.js.map () 28.8 kB [rendered] chunk {8} 8.js, 8.js.map () 48.7 kB [rendered] chunk {9} 9.js, 9.js.map () 48.7 kB [rendered] chunk {10} 10.js, 10.js.map () 35.2 kB [rendered] chunk {11} 11.js, 11.js.map () 35.6 kB [rendered] chunk {12} 12.js, 12.js.map () 27.3 kB [rendered] chunk {13} 13.js, 13.js.map () 27.3 kB [rendered] chunk {14} 14.js, 14.js.map () 18.5 kB [rendered] chunk {15} 15.js, 15.js.map () 18.5 kB [rendered] chunk {16} 16.js, 16.js.map () 28.7 kB [rendered] chunk {17} 17.js, 17.js.map () 29.4 kB [rendered] chunk {18} 18.js, 18.js.map () 22.5 kB [rendered] chunk {19} 19.js, 19.js.map () 22.7 kB [rendered] chunk {20} 20.js, 20.js.map () 25.6 kB [rendered] chunk {21} 21.js, 21.js.map () 25.6 kB [rendered] chunk {22} 22.js, 22.js.map () 41 kB [rendered] chunk {23} 23.js, 23.js.map () 42.6 kB [rendered] chunk {24} 24.js, 24.js.map () 29.3 kB [rendered] chunk {25} 25.js, 25.js.map () 30.2 kB [rendered] chunk {26} 26.js, 26.js.map () 15.4 kB [rendered] chunk {27} 27.js, 27.js.map () 15.4 kB [rendered] chunk {28} 28.js, 28.js.map () 21.1 kB [rendered] chunk {29} 29.js, 29.js.map () 21.3 kB [rendered] chunk {30} 30.js, 30.js.map () 36.3 kB [rendered] chunk {31} 31.js, 31.js.map () 36.3 kB [rendered] chunk {32} 32.js, 32.js.map () 29.3 kB [rendered] chunk {33} 33.js, 33.js.map () 30.2 kB [rendered] chunk {34} 34.js, 34.js.map () 20.9 kB [rendered] chunk {35} 35.js, 35.js.map () 20.9 kB [rendered] chunk {36} 36.js, 36.js.map () 29.1 kB [rendered] chunk {37} 37.js, 37.js.map () 29.3 kB [rendered] chunk {38} 38.js, 38.js.map () 22.2 kB [rendered] chunk {39} 39.js, 39.js.map () 22.4 kB [rendered] chunk {40} 40.js, 40.js.map () 19.8 kB [rendered] chunk {41} 41.js, 41.js.map () 20.1 kB [rendered] chunk {42} 42.js, 42.js.map () 20 kB [rendered] chunk {43} 43.js, 43.js.map () 20.3 kB [rendered] chunk {44} 44.js, 44.js.map () 26.8 kB [rendered] chunk {45} 45.js, 45.js.map () 27.6 kB [rendered] chunk {46} 46.js, 46.js.map () 21.8 kB [rendered] chunk {47} 47.js, 47.js.map () 21.9 kB [rendered] chunk {48} 48.js, 48.js.map () 21.8 kB [rendered] chunk {49} 49.js, 49.js.map () 21.9 kB [rendered] chunk {50} 50.js, 50.js.map () 21.9 kB [rendered] chunk {51} 51.js, 51.js.map () 21.9 kB [rendered] chunk {52} 52.js, 52.js.map () 23.5 kB [rendered] chunk {53} 53.js, 53.js.map () 23.5 kB [rendered] chunk {54} 54.js, 54.js.map () 26.8 kB [rendered] chunk {55} 55.js, 55.js.map () 27.6 kB [rendered] chunk {56} 56.js, 56.js.map () 23.8 kB [rendered] chunk {57} 57.js, 57.js.map () 24.1 kB [rendered] chunk {58} 58.js, 58.js.map () 21.6 kB [rendered] chunk {59} 59.js, 59.js.map () 21.8 kB [rendered] chunk {60} 60.js, 60.js.map () 20.9 kB [rendered] chunk {61} 61.js, 61.js.map () 20.9 kB [rendered] chunk {62} 62.js, 62.js.map () 28.4 kB [rendered] chunk {63} 63.js, 63.js.map () 28.6 kB [rendered] chunk {64} 64.js, 64.js.map () 20 kB [rendered] chunk {65} 65.js, 65.js.map () 20.2 kB [rendered] chunk {66} 66.js, 66.js.map () 21.9 kB [rendered] chunk {67} 67.js, 67.js.map () 21.9 kB [rendered] chunk {68} 68.js, 68.js.map () 41.5 kB [rendered] chunk {69} 69.js, 69.js.map () 43.1 kB [rendered] chunk {70} 70.js, 70.js.map () 29.1 kB [rendered] chunk {71} 71.js, 71.js.map () 29.3 kB [rendered] chunk {72} 72.js, 72.js.map () 22.5 kB [rendered] chunk {73} 73.js, 73.js.map () 22.7 kB [rendered] chunk {74} 74.js, 74.js.map () 21.6 kB [rendered] chunk {75} 75.js, 75.js.map () 21.8 kB [rendered] chunk {76} 76.js, 76.js.map () 34.3 kB [rendered] chunk {77} 77.js, 77.js.map () 34.4 kB [rendered] chunk {78} 78.js, 78.js.map () 35.8 kB [rendered] chunk {79} 79.js, 79.js.map () 35.8 kB [rendered] chunk {80} 80.js, 80.js.map () 22.9 kB [rendered] chunk {81} 81.js, 81.js.map () 23.4 kB [rendered] chunk {82} 82.js, 82.js.map () 48.7 kB [rendered] chunk {83} 83.js, 83.js.map () 48.7 kB [rendered] chunk {84} 84.js, 84.js.map () 18 kB [rendered] chunk {85} 85.js, 85.js.map () 18.1 kB [rendered] chunk {86} 86.js, 86.js.map () 35.8 kB [rendered] chunk {88} 88.js, 88.js.map () 18.5 kB [rendered] chunk {89} 89.js, 89.js.map () 18.5 kB [rendered] chunk {90} 90.js, 90.js.map () 23.9 kB [rendered] chunk {91} 91.js, 91.js.map () 24.2 kB [rendered] chunk {92} 92.js, 92.js.map () 21.6 kB [rendered] chunk {93} 93.js, 93.js.map () 21.8 kB [rendered] chunk {94} 94.js, 94.js.map () 21.6 kB [rendered] chunk {95} 95.js, 95.js.map () 21.8 kB [rendered] chunk {96} 96.js, 96.js.map () 27 kB [rendered] chunk {97} 97.js, 97.js.map () 27.5 kB [rendered] chunk {98} 98.js, 98.js.map () 18 kB [rendered] chunk {99} 99.js, 99.js.map () 18.1 kB [rendered] chunk {100} 100.js, 100.js.map () 21.4 kB [rendered] chunk {101} 101.js, 101.js.map () 21.6 kB [rendered] chunk {102} 102.js, 102.js.map () 23.1 kB [rendered] chunk {103} 103.js, 103.js.map () 23.4 kB [rendered] chunk {104} 104.js, 104.js.map () 21.1 kB [rendered] chunk {105} 105.js, 105.js.map () 21.3 kB [rendered] chunk {106} 106.js, 106.js.map () 32.1 kB [rendered] chunk {107} 107.js, 107.js.map () 32.1 kB [rendered] chunk {108} 108.js, 108.js.map () 23.5 kB [rendered] chunk {109} 109.js, 109.js.map () 23.5 kB [rendered] chunk {110} 110.js, 110.js.map () 20.1 kB [rendered] chunk {111} 111.js, 111.js.map () 20.1 kB [rendered] chunk {112} 112.js, 112.js.map () 35.7 kB [rendered] chunk {113} 113.js, 113.js.map () 36.1 kB [rendered] chunk {114} 114.js, 114.js.map () 35.7 kB [rendered] chunk {115} 115.js, 115.js.map () 36.1 kB [rendered] chunk {116} 116.js, 116.js.map () 13.7 kB [rendered] chunk {117} 117.js, 117.js.map () 13.7 kB [rendered] chunk {118} 118.js, 118.js.map () 14.3 kB [rendered] chunk {119} 119.js, 119.js.map () 14.3 kB [rendered] chunk {120} 120.js, 120.js.map () 9.86 kB [rendered] chunk {121} 121.js, 121.js.map () 9.87 kB [rendered] chunk {122} 122.js, 122.js.map () 36.6 kB [rendered] chunk {123} 123.js, 123.js.map () 36.7 kB [rendered] chunk {124} 124.js, 124.js.map () 36.7 kB [rendered] chunk {125} 125.js, 125.js.map () 36.9 kB [rendered] chunk {126} 126.js, 126.js.map () 3.97 kB [rendered] chunk {127} 127.js, 127.js.map () 3.14 kB [rendered] chunk {128} 128.js, 128.js.map () 3.19 kB [rendered] chunk {129} 129.js, 129.js.map () 12.7 kB [rendered] chunk {130} 130.js, 130.js.map () 12.7 kB [rendered] chunk {131} 131.js, 131.js.map () 21.6 kB [rendered] chunk {132} 132.js, 132.js.map () 21.6 kB [rendered] chunk {133} 133.js, 133.js.map () 13.4 kB [rendered] chunk {134} 134.js, 134.js.map () 13.4 kB [rendered] chunk {135} 135.js, 135.js.map () 21.2 kB [rendered] chunk {136} 136.js, 136.js.map () 21.2 kB [rendered] chunk {137} 137.js, 137.js.map () 1.73 kB [rendered] chunk {138} 138.js, 138.js.map () 9.7 kB [rendered] chunk {139} 139.js, 139.js.map () 9.72 kB [rendered] chunk {140} 140.js, 140.js.map () 9.87 kB [rendered] chunk {141} 141.js, 141.js.map () 9.88 kB [rendered] chunk {142} 142.js, 142.js.map () 4.94 kB [rendered] chunk {143} 143.js, 143.js.map () 5 kB [rendered] chunk {144} 144.js, 144.js.map () 10.1 kB [rendered] chunk {145} 145.js, 145.js.map () 10.1 kB [rendered] chunk {146} 146.js, 146.js.map () 10.4 kB [rendered] chunk {147} 147.js, 147.js.map () 10.4 kB [rendered] chunk {148} 148.js, 148.js.map () 10.3 kB [rendered] chunk {149} 149.js, 149.js.map () 10.4 kB [rendered] chunk {150} 150.js, 150.js.map () 13.4 kB [rendered] chunk {151} 151.js, 151.js.map () 13.4 kB [rendered] chunk {152} 152.js, 152.js.map () 2.51 kB [rendered] chunk {153} 153.js, 153.js.map () 2.54 kB [rendered] chunk {154} 154.js, 154.js.map () 3.51 kB [rendered] chunk {155} 155.js, 155.js.map () 3.59 kB [rendered] chunk {156} 156.js, 156.js.map () 7.16 kB [rendered] chunk {157} 157.js, 157.js.map () 7.32 kB [rendered] chunk {158} 158.js, 158.js.map () 3.51 kB [rendered] chunk {159} 159.js, 159.js.map () 3.58 kB [rendered] chunk {main} main.js, main.js.map (main) 142 kB [initial] [rendered] chunk {160} 160.js, 160.js.map () 2.36 kB [rendered] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [r endered] chunk {runtime} runtime.js, runtime.js.map (runtime) 9.06 kB [entry] [rendered] chunk {styles} styles.js, styles.js.map (styles) 35.8 kB [initial] [rendered] chunk {tabs-tabs-module} tabs-tabs-module.js, tabs-tabs-module.js.map (tabs-tabs -module) 25.9 kB [rendered] chunk {vendor} vendor.js, vendor.js.map (vendor) 4.36 MB [initial] [rendered] chunk {161} 161.js, 161.js.map () 14.7 kB [rendered] chunk {162} 162.js, 162.js.map () 8.11 kB [rendered] chunk {163} 163.js, 163.js.map () 1.39 kB [rendered] chunk {164} 164.js, 164.js.map () 1.39 kB [rendered] chunk {165} 165.js, 165.js.map () 5.15 kB [rendered] > cordova build android --release ANDROID_HOME=F:android-sdk-windows JAVA_HOME=C:Program FilesJavajdk1.8.0 Subproject Path: CordovaLib Incremental java compilation is an incubating feature. :preBuild UP-TO-DATE :preReleaseBuild UP-TO-DATE :checkReleaseManifest :CordovaLib:preBuild UP-TO-DATE :CordovaLib:preReleaseBuild UP-TO-DATE :CordovaLib:checkReleaseManifest :CordovaLib:prepareReleaseDependencies :CordovaLib:compileReleaseAidl :CordovaLib:compileReleaseNdk UP-TO-DATE :CordovaLib:compileLint :CordovaLib:copyReleaseLint UP-TO-DATE :CordovaLib:mergeReleaseShaders :CordovaLib:compileReleaseShaders :CordovaLib:generateReleaseAssets :CordovaLib:mergeReleaseAssets :CordovaLib:mergeReleaseProguardFiles :CordovaLib:packageReleaseRenderscript UP-TO-DATE :CordovaLib:compileReleaseRenderscript :CordovaLib:generateReleaseResValues :CordovaLib:generateReleaseResources :CordovaLib:packageReleaseResources :CordovaLib:processReleaseManifest :CordovaLib:generateReleaseBuildConfig :CordovaLib:processReleaseResources :CordovaLib:generateReleaseSources :CordovaLib:incrementalReleaseJavaCompilationSafeguard :CordovaLib:compileReleaseJavaWithJavac :CordovaLib:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). ע: ijЩ�����ļ�ʹ�û�����ѹ�ʱ�� API�� ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣 :CordovaLib:processReleaseJavaRes UP-TO-DATE :CordovaLib:transformResourcesWithMergeJavaResForRelease :CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease :CordovaLib:mergeReleaseJniLibFolders :CordovaLib:transformNative_libsWithMergeJniLibsForRelease :CordovaLib:transformNative_libsWithSyncJniLibsForRelease :CordovaLib:bundleRelease :prepareAndroidCordovaLibUnspecifiedReleaseLibrary :prepareReleaseDependencies :compileReleaseAidl :compileReleaseRenderscript :generateReleaseBuildConfig :generateReleaseResValues :generateReleaseResources :mergeReleaseResources :processReleaseManifest :processReleaseResources :generateReleaseSources :incrementalReleaseJavaCompilationSafeguard :compileReleaseJavaWithJavac :compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). ע: F:GitCodemyAppplatformsandroidsrcorgapachecordovasplashscreenSplash Screen.javaʹ�û�����ѹ�ʱ�� API�� ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣 :compileReleaseNdk UP-TO-DATE :compileReleaseSources :lintVitalRelease :mergeReleaseShaders :compileReleaseShaders :generateReleaseAssets :mergeReleaseAssets :transformClassesWithDexForRelease :mergeReleaseJniLibFolders :transformNative_libsWithMergeJniLibsForRelease :processReleaseJavaRes UP-TO-DATE :transformResourcesWithMergeJavaResForRelease :packageRelease :assembleRelease :cdvBuildRelease BUILD SUCCESSFUL Total time: 22.363 secs Built the following apk(s): F:/GitCode/myApp/platforms/android/build/outputs/apk/android-release-uns igned.apk