Configuring the right Android-API level for my project

我怕爱的太早我们不能终老 提交于 2019-12-13 19:12:14

问题


In my application I want to target all Android Versions >= 8 (Push-Notification required), but I'm having a hard time understanding the right combination of APIs / dependencies I need for my project setup.

The project will need Google APIs for location based services, and I need to / want to use ActionBarSherlock for ActionBar support.

Is this setup correct?


AndroidManifest.xml:

(1)

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

<application
    android:theme="@style/Theme.Sherlock.Light" >
    ...

Libs:

(2) I added android-support-v4.jar

Project-properties:

(3) Set to Google-APIs 16

ActionBarSherlock:

(4) I followed the video at ActionBar-FAQ to set-up ABS as a library project, and I have it set to Android Level 16 in its project proberties, and added android-support-v4.jarin its lib folder.


I know it's kind of a basic question, but I'm not sure if I've chosen the right setup. I'm especially wondering if (3) is correct or if I am supposed to set the overall API-Level to 8?

Update 1: I also have a problem understanding the mechanisms of support.jar. If I set my build-target to maximum - how does the system make sure that high-level functionality (like fragments) work in lower APIs (like 8) . Is this done automagically, or do I have to manually code against support packages? Update 2 Regarding support.jar I will have to know what features I'm using and will have to code against support.jar. If I fail and use a feature which is too advanced, a ClassCastException on lower API levels will be thrown...?

Any help appreciated. Also: I'm a beginner, so answers with some background information would be highly regarded :)

Thanks!


回答1:


That looks right. As described in the video on ActionBarSherlock.com you want your step #3 set to the highest "Project Build Target" available for your version of ActionBarSherlock. So if you have ABS 4.1.0, you want Platform 4.1, API 16.

Have you also set up the ABS project as a library? Your project's dependencies should have both:

  • < Your-ABS-Library >.jar
  • android-support-v4.jar



回答2:


Your setting is correct. If you set it to version 8 (3) you will not able to compile it. As ActionBarSherlock needs at least api level 14.

But setting it this way, one thing to take into account is, all the Android API you are using must be API <= level 8. That is you cannot use feature that is not included in API level 8, else the application will crash with ClassNotFoundException or MethodNotFound exception.

As for the Fragment, you should always choose the support library Fragment. That is you should import android.support.v4.app.Fragment, instead of android.app.Fragment.

For Update 2:

Yes it will be thrown during runtime, it makes your apps not workable. But sure enough you can avoid this pitfall by checking the current phone API level.

For example

if(android.os.Build.VERSION.SDK_INT >= 11) {
    // API that supported in API >= 11
}
else {
    // API that supported in API < 11
}

I've actually verified this myself. You could try verify it by using Emulator too, like Running version 8 Emulator and Run code with API version >= 8 code.




回答3:


I would recommend you to set the Build SDK to API 15. I'm using that too with Sherlock ActionBar and everything works fine.



来源:https://stackoverflow.com/questions/11710544/configuring-the-right-android-api-level-for-my-project

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