你如何为 ionic/cordova 构建和部署到旧版本的 android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24522921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you build and deploy to an older version of android for ionic / cordova
提问by Derek
Using Ionic 1.0.0 beta-8
使用 Ionic 1.0.0 beta-8
After creating a new app, I built and deployed it to a Nexus 5 emulator and it worked fine. But when I tried to debug it on my Android 2.2 phone, I got this error:
创建新应用程序后,我构建并将其部署到 Nexus 5 模拟器,它运行良好。但是当我尝试在我的 Android 2.2 手机上调试它时,我收到了这个错误:
....
-post-build:
[move] Moving 1 file to /home/admin/code/projects/myapp/ionic/platforms/android/ant-build
[move] Moving 1 file to /home/admin/code/projects/myapp/ionic/platforms/android/CordovaLib/ant-build
debug:
BUILD SUCCESSFUL
Total time: 6 seconds
WARNING : No target specified, deploying to device 'I8972b56ddac'.
Using apk: /home/admin/code/projects/myapp/ionic/platforms/android/ant-build/HelloCordova-debug-unaligned.apk
Installing app on device...
/home/admin/code/projects/myapp/ionic/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
ERROR: Failed to launch application on device: ERROR: Failed to install apk to device: pkg: /data/local/tmp/HelloCordova-debug-unaligned.apk
Failure [INSTALL_FAILED_OLDER_SDK]
Error: /home/admin/code/projects/myapp/ionic/platforms/android/cordova/run: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Process.ChildProcess._handle.onexit (child_process.js:822:5)
ERROR: Unable to run app on platform android. Please see console for more info.
Exiting.
How do I make the build work in ionic/cordova for android 4.x.x phones as well as android 2.2 phones?
如何使构建在 ionic/cordova 中适用于 android 4.xx 手机和 android 2.2 手机?
回答by vdj4y
this question is similar to yours. stackoverflow
这个问题和你的类似。 堆栈溢出
go to your AndroidManifest.xml, find these to control your sdk buildversion.
转到您的 AndroidManifest.xml,找到这些来控制您的 sdk 构建版本。
<preference name="android-minSdkVersion" value="XX"> // value is the API LEVEL
<preference name="android-targetSdkVersion" value="XX">
*targetSdk = tell phonegap which android build version to use,
*MinSdk is to limit user who want to download it.
check the API LEVEL of android build here.
*targetSdk = 告诉 phonegap 使用哪个 android build 版本,
*MinSdk 是限制想要下载它的用户。
在此处检查 android build 的 API LEVEL 。
In Your case:for android 2.2, use value= 8(API level 8)
在您的情况下:对于 android 2.2,使用 value= 8(API level 8)
<preference name="android-minSdkVersion" value="8"> //android 2.2
<preference name="android-targetSdkVersion" value="17"> //android 4.2
NOTE: I doubt android 2.2(API level 8) can run API level 17(android 4.2).
注意:我怀疑 android 2.2(API 级别 8)可以运行 API 级别 17(android 4.2)。
回答by Paullo
According to Ionic Platform notes, Ionic targets iPhone and Android devices (currently). It also support iOS 6+, and Android 4.0+ (though 2.3 should work). However, since there are a lot of different Android devices, it's possible certain ones might not work. Ionic did not guaranty for Android 2.3 hence Android 2.2 will be out of scope.
根据Ionic Platform 说明,Ionic 的目标是 iPhone 和 Android 设备(目前)。它还支持 iOS 6+ 和 Android 4.0+(尽管 2.3 应该可以工作)。但是,由于有很多不同的 Android 设备,因此某些设备可能无法正常工作。Ionic 不保证 Android 2.3,因此 Android 2.2 将超出范围。
Hence, I think that is the reason why you are having challenges.
因此,我认为这就是您遇到挑战的原因。
回答by Eno
FYI, Google back-ported features from Honeycomb and again from later versions of Android into a "compatibility" library. You might be able to install that and get your app working on older versions of Android. You would need to update your Android SDK and install this library.
仅供参考,Google 将 Honeycomb 和更高版本的 Android 中的功能向后移植到“兼容性”库中。您也许可以安装它并使您的应用程序在旧版本的 Android 上运行。您需要更新您的 Android SDK 并安装此库。
See Android Support Librarydocs.
请参阅Android 支持库文档。
If you're using Ionic, you could add a hook script that copies the library into your project when you add Android as a platform or start a build.
如果您使用的是 Ionic,您可以添加一个钩子脚本,在您添加 Android 作为平台或开始构建时将库复制到您的项目中。
回答by Yuvraj Patil
Change value of "android-minSdkVersion"
in config.xml
of your ionic project. It should look like below:
更改离子项目的"android-minSdkVersion"
in值config.xml
。它应该如下所示:
<preference name="android-minSdkVersion" value="14"/>
回答by TheBearF8
It would appear that cdvCompileSdkVersion is used to determine build SDK and NOT targetSdkVersion as one would use in native android apps.
看起来 cdvCompileSdkVersion 用于确定构建 SDK 而不是 targetSdkVersion ,就像在本机 Android 应用程序中使用的那样。