问题
Google added a new ART runtime with Android 4.4. How can I target my apk to both ART runtime and Dalvik runtime?
回答1:
This change is without consequences for the developers. Your app remains exactly the same, nothing to do there. Just make sure you target API 19 so that your app is available for KitKat users. They will decide in their phone if they want to use ART or Dalvik.
回答2:
This is an old question now, but very key. I confirmed today, all my apps break with ART+Android-5 on Nexus-x tablets. ART does more strict JNI checks, so if your app uses java plus native code,the move from Dalvik to ART may break app operation. For me, it has been a complete show-stop. I have 6 apps in Google Store and all fail now on Nexus devices running Android 5.x, yet they run correctly on all 4.x.x (Kitkat) series devices. This is most frustrating. I am going thru all the ART/ Dalvik questions and answers on this site. ART and Android-5.x is very significant change, so the question asked here "How do I target my apk to both Dalvik and ART?" is a key and very critical question. Time has proven that the responses given suggesting "No difference to developers" is manifestly incorrect. It certainly is in our case.
Two specific issues are documented, and I quote from "Verifying App Behavior on the Android Runtime (ART)":
1) " Checking JNI code for garbage-collection issues ART has a compacting garbage collector under development on the Android Open Source Project (AOSP). Once the compacting garbage collector is in use, objects may be moved in memory. If you use C/C++ code, do not perform operations that are incompatible with compacting GC. We have enhanced CheckJNI to identify some potential issues (as described in JNI Local Reference Changes in ICS)." In other words, the new ART memory mangement model may break your existing (and operational) native code.
2) " Error handling ART's JNI throws errors in a number of cases where Dalvik didn’t.".
A limited explanation of some of the issues that will cause errors to be thrown by the Android 5.x ART is provided in: http://developer.android.com/guide/practices/verifying-apps-art.html#JNI_Issues
The forward-compatibility solution currently being adopted among users of Android devices running ART and 5.x, and facing non-operational apps, is a downgrade to Android 4.4.4, by unlocking the bootloader, wiping the device memory, and installing system image "Hammerhead", in the case of those running Nexus series tablets. For Samsung tablets, a tutorial is available at: http://forums.androidcentral.com/samsung-galaxy-s5/489071-tutorial-downgrade-samsung-galaxy-s5-5-0-4-4-kitkat.html
回答3:
The dalvik or ART is only the runtime in the Android. As an app developer, you don't have to care about these differences. All you have to care about is your app's API level which is describing the dependence of the Android OS version.
And in Android 4.4, ART is only a development which is NOT the default runtime even if the release note describing that ART will make app use less memory and run quickly. If you want to find the different, you can wait for the next version of Android. In the opensource, I found the ART has been setting the default runtime selection.
回答4:
For most apps ART will work just fine.
It is, however, not 100% compatible as something that work on Dalvik may not work on ART
Please visit this link for more information.
来源:https://stackoverflow.com/questions/19952029/android-apk-compile-to-art-runtime-and-dalvik-runtime