简体   繁体   English

你如何为 ionic/cordova 构建和部署到旧版本的 android

[英]How do you build and deploy to an older version of android for ionic / cordova

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.创建新应用程序后,我构建并将其部署到 Nexus 5 模拟器,它运行良好。 But when I tried to debug it on my Android 2.2 phone, I got this error:但是当我尝试在我的 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.xx phones as well as android 2.2 phones?如何使构建在 ionic/cordova 中适用于 android 4.xx 手机和 android 2.2 手机?

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, *targetSdk = 告诉 phonegap 使用哪个 android build 版本,
*MinSdk is to limit user who want to download it. *MinSdk 是为了限制想要下载它的用户。
check the API LEVEL of android build here .此处检查 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)。

According to Ionic Platform notes , Ionic targets iPhone and Android devices (currently).根据Ionic Platform 说明,Ionic 的目标是 iPhone 和 Android 设备(目前)。 It also support iOS 6+, and Android 4.0+ (though 2.3 should work).它还支持 iOS 6+ 和 Android 4.0+(尽管 2.3 应该可以工作)。 However, since there are a lot of different Android devices, it's possible certain ones might not work.但是,由于有很多不同的 Android 设备,因此某些设备可能无法正常工作。 Ionic did not guaranty for Android 2.3 hence Android 2.2 will be out of scope. Ionic 不保证 Android 2.3,因此 Android 2.2 将超出范围。

Hence, I think that is the reason why you are having challenges.因此,我认为这就是您遇到挑战的原因。

FYI, Google back-ported features from Honeycomb and again from later versions of Android into a "compatibility" library.仅供参考,Google 将 Honeycomb 和更高版本的 Android 中的功能向后移植到“兼容性”库中。 You might be able to install that and get your app working on older versions of Android.您也许可以安装它并使您的应用程序在旧版本的 Android 上运行。 You would need to update your Android SDK and install this library.您需要更新您的 Android SDK 并安装此库。

See Android Support Library docs.请参阅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 作为平台或开始构建时将库复制到您的项目中。

Change value of "android-minSdkVersion" in config.xml of your ionic project.更改 ionic 项目的config.xml"android-minSdkVersion"值。 It should look like below:它应该如下所示:

<preference name="android-minSdkVersion" value="14"/>

看起来 cdvCompileSdkVersion 用于确定构建 SDK 而不是 targetSdkVersion ,就像在本机 Android 应用程序中使用的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM