Compile android project with a higher sdk

假如想象 提交于 2019-12-11 03:29:01

问题


I have a question about android sdks. I'm developing an android application and it must be work on Android 2.3.3 and higher.

Because I need to use "android-support-v7-appcompat" library, I need to compile the project with Android 4 or higher. If I try to compile with Android 2.3.3, the project doesn't compile.

So what happens if I compile the project with Android 4? Would it work on Android 2.3.3?

Of course I would set in AndroidManifest.


回答1:


In any case you should properly define minSDK and targetSDK in manifest file. When you compile for example with API 19 (KitKat) and you set as minSDK API 10 everything should work on your 2.3.3 Android.

However if you used in your code some methods, constants that are not available on 2.3.3 you will get warnings/errors in Eclipse (I bet in Android Studio as well). For example:

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // before JELLY_BEAN_MR2 code;
        // methods, constants available for example from API 1
    } else {
        // after JELLY_BEAN_MR2 code
        // here are new methods,constants available from GINGERBREAD_MR1 and after
    }

so here your app will execute something in a two different way depending on Android version it is running on... In case you don't compile with API equals or higher of JELLY_BEAN_MR2 you would not even be able to compile because before, constant JELLY_BEAN_MR2 was not available in API... However when you compile with higher API everything will be compiled properly and app will work on earlier versions without problems.

If you leave code like this warning will appear but @SuppressLint("NewApi") before calling method should remove it with no further problems.

Hope it helped and it is clear now.. ;)

Cheers




回答2:


Its Depends on your target selected for ex:

    <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />


来源:https://stackoverflow.com/questions/20213268/compile-android-project-with-a-higher-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!