How can I use a library made for Android above 1.6 but targeted at 2.3.3?
I'm trying to use some Android library on my project but I'm having a problem with minimum SDK version and target SDK version. The library I'm talking about is this ActionBar. It says on the readme that "This projects aims to provide a reusable action bar component for Android 1.6 and up to 3.0".
I want to target my application at 1.6 (if I happen to need some higher APIs, I'll change it when I have to) and so I created an Eclipse project for the ActionBar with the build target as API Level 4 (1.6). Despite the library minSdkVersion
being set to 4 (and targetSdkVersion
set to 10) the project doesn't compile though. There's 3 errors to be exact that I t开发者_开发技巧hink belong to API Level 10 (2.3.3), at least one of them I know for sure cause it's trying to use Build.VERSION_CODES.GINGERBREAD
, which doesn't exist on API Level 4.
How come the library supports "Android 1.6 and up to 3.0" and doesn't even compile with 1.6 in mind cause it's using stuff from a higher API?
Fine I thought, let's set the API Level to 10 and see what happens. The errors are gone and now I just have a warning, just like this one. I can live with that, it's no biggie (but if there's any way to remove that from Eclipse, let me know please).
Then I created my project targeting 1.6, I referenced the library into my project but I can't compile/run it because the same errors as above apply also here.
How can I workaround this? If the library supposedly supports "Android 1.6 and up to 3.0", how can I use on my project that targets Android 1.6?
I'm not familiar with the library you're talking about, but I think you don't fully understand the difference between setting a build/compile target and the minimum SDK version. It's perfectly normal to set your project properties to build against v10 and targetSdk to 10, and then the minimum to 4. Assuming the library is written properly, then it will remain compatible with older versions. It will do this by checking which version of Android is running before trying to access APIs which don't exist on the older versions. However, if the project properties aren't set to 10, then it wouldn't know what to do if it were running on a more 'modern' version of Android.
You can see a related discussion of the minSdk versus targetSdk settings in my other answer here.
Try changing the Build.VERSION_CODES.GINGERBREAD into Build.VERSION_CODES.DONUT. Not sure why you need the Build.VERSION_CODES.GINGERBREAD check if you're targetting at 1.6
精彩评论