Should I use "android.maxSdkVersion" in the manifest.xml file? - android

Should I use android.maxSdkVersion in manifest.xml file? Because I read in documents that I should not use this in manifest.xml file. And as regards most version of android devices are 2.3 to higher. What is your opinion?

Google stated at Android Developers:
Warning: Declaring this attribute is not recommended. First, there is no need to set the attribute as means of blocking deployment of your application onto new versions of the Android platform as they are released. By design, new versions of the platform are fully backward-compatible. Your application should work properly on new versions, provided it uses only standard APIs and follows development best practices. Second, note that in some cases, declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level. Most devices on which your application is likely to be installed will receive periodic system updates over the air, so you should consider their effect on your application before setting this attribute.
Syntax:
<uses-sdk
android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
However if you use the new Gradle then android:minSdkVersion="integer" and android:targetSdkVersion="integer" will always be overridden in the Gradle scripts.
I suggest you not to use it.
Here is a guide for more detailed information:
Android Developers - uses-sdk-element in manifest

Related

How can I add foregroundServiceType to a library manifest while maintaining backwards compatibility?

My library project has a location service, and per Android Q requirements it sets the android:foregroundServiceType="location" attribute in the manifest. When an app module uses my library and compiles against API level 28, it fails with the following error:
AndroidManifest.xml:57: AAPT: error: attribute android:foregroundServiceType not found.
How can my library maintain compatibility with older versions, while making sure the functionality works on Android Q?
I had same error and after migrating to Androidx and updating compileSdkVersion from 28 to 29 my issue was resolved. So please do these changes and you can get your solution
My goal is to avoid breaking anyone's build when the library version is updated, and at the same time avoid forcing the developer to compile against API 29. It seems I have two choices:
Provide a separate library so that developers compiling against API 28 and lower don't get impacted;
warn developers targeting the new version to replace the service definition in the manifest using tools:node="replace".
The problem with the first approach is that I will need to maintain two libraries for some time. The problem with the second is that developers must remember to revert the change once they update the SDK version.
In my case, I will go with the second approach. By passing an explicit foreground service type to the startForeground method when targeting Android Q, I can cause a crash if the type is not set in the manifest. The developer can therefore catch this when targeting Android Q and revert the manifest change to fix it.

Xamarin.Android check API Level

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

How to support lowest possible API version?

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

adding android:tragetSdkVersion= "14" in maifest for application developed for 2.3.3 version, is it a good idea?

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

Android: android:targetSdkVersion and android:maxSdkVersion

How to use android:targetSdkVersion and android:maxSdkVersion xml attributes?
The attributes android:minSdkVersion, android:maxSdkVersion let you specify the range of devices your app will support which will be used by Google to filter its content.
Say you have Android version 11 i.e. Honeycomb on you device and I make an app and I specify android:minVersion = "14" (i.e. ICS), then my app will not be shown in your device's Play Store, similarly the android:maxVersion serves the same purpose.
The attribute android:targetSdkVersion is used by the developers to specify the platform they are targeting the most, lets say 70% of Android device users have version 10 i.e Gingerbread on their phones so it will be a better option for the developer to test the app on 2.3 devices and specify android:targetSdkVersion to the same.
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
Description:
Lets you express an application's compatibility with one or more versions of the Android platform, by means of an API Level integer. The API Level expressed by an application will be compared to the API Level of a given Android system, which may vary among different Android devices.
Attributes:
android:minSdkVersion
An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.
android:targetSdkVersion
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
android:maxSdkVersion
An integer designating the maximum API Level on which the application is designed to run.
In Android 1.5, 1.6, 2.0, and 2.0.1, the system checks the value of this attribute when installing an application and when re-validating the application after a system update. In either case, if the application's maxSdkVersion attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed. In the case of re-validation after system update, this effectively removes your application from the device.
More in Details
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eample.tut"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />****
<uses-permission android:name="android.permission.INTERNET"/>
<application
....
</application>
</manifest>
Just to add to what Alexis wrote, these XML tags are how the Google Play Store knows which devices your application can deploy to. It will also affect which levels of the API you can use during development. If you're ever wondering exactly how far back you should support, check out the pie graph on the Android Dashboard page to see the breakdown of current devices.
In your android manifest write (example):
<uses-sdk
android:maxSdkVersion="16"
android:minSdkVersion="10"
android:targetSdkVersion="10" />
See this for more informations.

Categories

Resources