I'm developing a Android library and I want to support as many API versions as possible. I have stumbled upon a problem with AsyncTask and found an answer here on SO. The proposed code to use is:
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute(params);
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
My question is, how do I include the proposed code AND support lowest possible API level? What API version should I reference? What should I write in the uses-sdk tag inte manifest?
Since the field THREAD_POOL_EXECUTOR in AsyncTask is only available from API level 11. Can this code be compiled to a lower level?
Thanks!
Assume that you line below exists in you manifest
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
This means that you are using features from API-17 but to ensure backwards compatibility your application may start on minimum API-8 (Froyo).
According to your example, using THREAD_POOL_EXECUTOR for API-17 or lower is OK. And running your code with Froyo device is OK too. Because THREAD_POOL_EXECUTOR field will not be used in this case.
In the manifest set android:minSdkVersion="minimumApiYouNeed", this is the lowest api you want to support, and the android:targetSdkVersion="maximumApi". This is the api that will be used to compile the code. This way you will be able to do things like what you wrote there, if you ever write something that is not supported by the minimum api, the editor will notify you, but it will work well if you do the checking it will work well
You will have to use API level 11 or higher unless you can find a library that works on an earlier API level that provides the THREAD_POOL_EXECUTOR implementation. Also, check to see if Google provides any backports or support libraries that would allow this to work before API 11.
This supports Android back to 2.1 (sdk version 7), but compiles the code against sdk version 17 (HoneyComb). You would have to add that tag to your manifest, of course.
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
Your project.properties should include this line:
# Project target.
target=Google Inc.:Google APIs:17
Related
I have an Android App that has been developed, compiled and released using the default SDK option
Use Compile using SDK Version
I need to make additions to this application, however I do not know what SDK it targeted at compiled time when it was last tested and released.
The problem being later API levels have different requirements, such as Authorization changes where you need to seek permission from the user. I can see from the code this does not do this, so it must be earlier.
Is there a way to know from source or the previous compiled .apk which SDK was used? I do not have permission to update all of the code to add in all of these authorization changes, just have a few small changes to do.
Maybe you can add your changes inside an if like this:
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.**TheVersionYouNeed**) {
// Your code
}
An .apk is just a zip file, so unzip it and look at the manifest xml file.
Near the top of the file you should find an element that can contain the min, target and max SDK.
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
You will be looking for the targetSdkVersion API level
re: https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
I made my game work on Android TV, it required Leanback library, which wants minSdkVersion to be 17. I must support API 16 too. What can I do?
When building, I get an error this suggestion:
Suggestion: use tools:overrideLibrary="android.support.v17.leanback" to force usage
What exactly does it do? Does it actually make my app still support API 16? What am I losing?
You can find the detailed information here.
Here is what it says:
tools:overrideLibrary marker
A special marker that can only be used with uses-sdk declaration to
override importing a library which minimum SDK version is more recent
than that application's minimum SDK version. Without such a marker,
the manifest merger will fail. The marker will allow users to select
which libraries can be imported ignoring the minimum SDK version.
And you need to do the following: In the main android manifest :
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="2"
tools:overrideLibrary="android.support.v17.leanback"/>
Hope this helps.
Can anyone explain regarding the Minimum Required SDK, Target SDK , Compile with options while creating an application.
If i set the minimum required SDK as API 8, Target SDK as API 16 and Compile with API 17,
will it work on Froyo devices in adroid?
If i want to use the methods introduced in API 16 or Library uses API 16, and want my app
to work on Froyo or ICS devices, how can i achieve this?
Thanks in advance.
You can use API-Level 16 methods only on devices that are Level 16 and higher. But you can check in your app and only call them when this is the case. Look into my small test-app which uses API-11-methods and runs from API-3 and up.
http://code.google.com/p/android-change-log/source/browse/trunk/src/sheetrock/panda/changelog/ChangeLog.java
Look at lines 40-41, 144-145 and 324-341. You don't need any third party libraries for this, but you need to put your higher API code in a separate class (lines 324-341).
Yes. But be careful not to include API higher than Froyo in your application
From my understanding, you can't, unless you use third party libraries. There are useful libraries out there which help you realise that:ViewPager and ActionBarSherlock.
Yes ofcourse for first question. If you use like this.
android:minSdkVersion="8"
android:targetSdkVersion="16"
For second. you can go for third party library if you import it, surely will work.For eg:
special features introduced in android 4.0 with tabs and swipe.But to overcome that
actionbar sherlock library been introduced which support in all version and in github.
Hope it helps you.
I want to add android:tragetSdkVersion= "14" in my manifest but I'm consufed as initially I developed my application for 2.3.3 version. So I used TabActivity for that. But TabActivity is deprecated in 4.0 version and according to the documentation, including android:tragetSdkVersion= "14" means system will not impose any forward compatibility to the app. So I wonder if it is good idea to include android:tragetSdkVersion= "14" in my manifest.
If you want to make it working on sdk 14, why are you leaving TabActivity in your code?
Otherwise, don't make sdk14 your target, and better to prevent users with version 4.0 or higher to install your application
You should use the v4 support libraries if you target higher SDK versions and also provide a minSdk:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
here is info about the support libraries
http://developer.android.com/tools/support-library/index.html
As recomended here http://developer.android.com/guide/practices/screens_support.html for compatibility reasons my AndroidManifest.xml contains this:
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
This generates warning in eclipse:
Attribute minSdkVersion (3) is lower
than the project target API level (4)
Are there any means to suppress this warning or get rid of it any other way? It is really annoying.
In short, there is no built-in way to do this that I know of.
Here's a discussion from last August.
And here is a Xavier Durochet's response.
It looks like you can manually remove it according to Mark Murphy's response in the first thread:
Or, you can modify SetupTask.java, eliminate this test (lines 297-308 in
the code indexed by Google Code Search), and build it into a custom
version of the Android Ant extension
There is a feature request that may deal with this, but who knows when it will be implemented.
The answer from 2011 is no longer accurate. It was fixed in ADT 17 according to this bug.
This warning is an usual one. I am using minSdkVersion to support Android 1.5 and I am building for Android 1.6 to support small screens. You can build your application with the latest Android 2.3 library, but still support a lower version.