Not targeting the latest versions of Android

AndroidStylesThemesWarningsManifest

Android Problem Overview


I have a warning when trying to test theme on latest Android SDK Package 4.2.

Here is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.themetest"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppBaseTheme" >
        <activity
            android:name="com.example.themetest.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

> Not targeting the latest versions of Android; compatibility modes > apply. Consider testing and updating this version. Consult the > android.os.Build.VERSION_CODES javadoc for > details. AndroidManifest.xml /ThemeTest line 7 Android Lint Problem

I am using a custom theme called 'AppBaseTheme'. My question is what exactly Consult the android.os.Build.VERSION_CODES javadoc.. How could I solve this problem?

Android Solutions


Solution 1 - Android

It says this because of targetSdkVersion="16". API 16 is Jellybean 4.1 and 4.1.1, while Jellybean 4.2 is API 17.

Try using:

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

Also, keep in mind that this is a Lint warning. These warning exist to help you better your code and make it easy to maintain, while being compatible with the latest Android changes. Ignoring this will not cause you any immediate problems.

EDIT: With Android 4.3, the latest SDK version is now 18, so you should use:

...
        android:targetSdkVersion="18" />

EDIT 2: With Android 4.4, the latest SDK version is now 19, so you should use:

...
        android:targetSdkVersion="19" />

EDIT 3: With Android L, you must use the following values, as described here:

compileSdkVersion="android-L"
minSdkVersion="L"
targetSdkVersion="L"

EDIT 4: With Android L's public release, you must use 21 instead:

...
        android:targetSdkVersion="21" />

20 was used for 4.4W, or for Android Wear.

EDIT 5: With Android M's public release, you must use 23 instead:

...
        android:targetSdkVersion="23" />

In the future please consult the official Android documentation to keep yourself up-to-date with the latest Android API Levels.

Solution 2 - Android

You should not use android:maxSdkVersion="17" because it means that if someone using your app updates its android OS to a version greater than 17, your app will be removed.

Solution 3 - Android

This lint message is telling you that compatibility mode will be automatically applied to any features you may have used that are not available in later versions than your declared targetSdkVersion of 16 (and, it is also telling you that there are such later versions - e.g., 17).

These automatic compatibility mode adjustments may not be as ideal as what you could accomplish yourself by using whatever features were added in later (than level 16) versions to replace the functionality of the level 16 ones that you may have used, which have been removed in later versions (if any). But everything should still continue to work in later versions (due to the adjustments made by the compatibility code that is automatically applied for running on versions higher than your declared targetSdkVersion's API level); it just may not work as well as your own custom detection of, and use of, the new features (when your app detects that it is running in the later versions that have those features) would have worked.

Here is a discussion, with examples, of minSdkLevel vs. targetSdkLevel:

https://stackoverflow.com/questions/4568267/android-min-sdk-version-vs-target-sdk-version/11176875#11176875

Another thing you will want to consider is the relationship of the Project Build Target (the level of the SDK used to compile your app) to the targetSdkLevel:

https://stackoverflow.com/questions/8938348/difference-between-build-target-sdk-in-eclipse-and-androidtargetsdkversion-in/15402516#15402516

Solution 4 - Android

Its a warning message if you want to solve it then you can set android:maxSdkVersion="17" but you have to take care of the fact that if someone currently using your app and upgrade his android OS to greater version than 17 then your app will automatically remove because of unsupported version.. So take care of this fact also..

Solution 5 - Android

Add xmlns:tools="http://schemas.android.com/tools" tools:ignore="OldTargetApi".

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.themetest"
    android:versionCode="1"
    android:versionName="1.0" xmlns:tools="http://schemas.android.com/tools" tools:ignore="OldTargetApi">

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

From: https://stackoverflow.com/questions/14161732/stuck-on-why-my-android-app-wont-work

Solution 6 - Android

Always go with the latest android version as your target SDK to get more benefits.

Targeting a recent API level also allows your app to take advantage of the platform's latest features to delight your users. Furthermore, as of Android 10 (API level 29), users see a warning when starting an app for the first time if the app targets Android 5.1 (API level 22) or lower.

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

Please refer to this developer site for more details.

https://developer.android.com/distribute/best-practices/develop/target-sdk

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEdy DeveloperView Question on Stackoverflow
Solution 1 - AndroidRaghav SoodView Answer on Stackoverflow
Solution 2 - AndroidClCfeView Answer on Stackoverflow
Solution 3 - AndroidCarlView Answer on Stackoverflow
Solution 4 - AndroidAnil ChahalView Answer on Stackoverflow
Solution 5 - AndroidkangearView Answer on Stackoverflow
Solution 6 - AndroidSelvaganesan SaminathanView Answer on Stackoverflow