what is the difference between tools:targetApi in the Manifest and target sdk in build.gradle? - android

I developed an app in Android and I want to limit the Android versions allowed to use it. So, in the build.gradle file, I put:
android {
namespace 'wamboo.example.videocompressor'
compileSdk 33
defaultConfig {
applicationId "wamboo.example.videocompressor"
minSdk 30
targetSdk 33
versionCode 2
versionName "2.0"
but I also saw this in the AndroidManifest file:
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.VideoCompressor"
tools:targetApi="31">
I was wondering if I need to change that tools:targetApi="31"> to tools:targetApi="33">?

tools:targetApi="x" is used by lint to specify which API level is supported by this element (in your case application)
tools:targetApi documentation
This tells the tools that you believe this element and any children are used only on the specified API level or higher. This stops lint from warning you if that element or its attributes are not available on the API level you specify as your minSdkVersion.
In your case, application has dataExtractionRules attribute, which was aded in API 31. Since your minSdk is 30, without tools:targetApi you will see a lint warning.
Answering your question, it's fine to leave it as 31, since it's the minimum version required by all attributes in the application element. Though it wouldn't harm to set it to 33 as well because it's only used by lint and won't affect the app in runtime.

Related

How use rounded icon on API 15

In my android project:
In my Manifest file:
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="28" />
<application
android:name="my_app_name"
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/l_icon"
android:roundIcon="#drawable/ic_launcher"
android:theme="#style/FacturaTheme" >
I can't build project.
I get warning message:
Attribute "roundIcon" is only used in API level 25 and higher (current min is 15)
I can't increment api level to 25. Because it's requirement to use api 15.
How I can fix this problem with round icon?
You have two solution:
Updating minimum sdk to 25 because the roundIcon is for Nougat(API 25) and above or remove roundIcon

App has become incompatible with some devices

I noticed recently that my app has become incompatible with some devices 'due to the APK's manifest' (explanation from Play developer console), devices which I know for a fact that were able to run the app. I've looked back at changes of the manifest and the only thing that caught my attention was this:
<uses-library android:name="org.apache.http.legacy" android:required="true" />
One device that seems to no longer be compatible with the app runs Android 4.4.2 and supports openGL ES 2.0.
Can this be the reason why this is happening? Should I replace the manifest line with the following gradle addition:
android {
useLibrary 'org.apache.http.legacy'
}
Additional info:
android {
compileSdkVersion 28
buildToolsVersion '28.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
...
}
}
and (the only other manifest requirement):
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Yes, it seems that manifest line influences device compatibility (massively) and the solution is to remove it and add the Gradle declaration.

How to prevent devices lower than Lollipop from installing my app?

How to prevent devices lower than Lollipop from installing my app from Google play?
Is there a solution from google play developer console or from the config file ?
You can specify that in your app's manifest file with <uses-sdk />. It has a android:minSdkVersion attribute that can be used to set a minimum. The Lollipop API level is 21. So if you want Lollipop and above, use:
<uses-sdk android:minSdkVersion="21" />
You probably already have a <uses-sdk /> node in your manifest. You can only have one, so you'd need to update your existing node.
https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
You can define it in your build.gradle
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
}

Not targeting the latest versions of Android

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?
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.
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.
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:
Android Min SDK Version vs. Target SDK Version
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:
Difference between "Build Target SDK" in Eclipse and android:targetSdkVersion in AndroidManifest.xml?
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
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..
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: Stuck on why my android app wont work?

installLocation identifier not found in eclipse Android package

when I tried to add
android:installLocation="auto"
in my AndroidManifest.xml file I found the following error in eclipse
error: No resource identifier found for attribute "installLocation" in package "android"
how to overcome this problem ?
edited :
My Manifest file is :
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0"
package="com.xxxx.yyyy">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:label="#string/app_name" android:icon="#drawable/icon">
<activity
android:screenOrientation="portrait"
android:name=".StarterActivity"
android:label="#string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name="GamePlayActivity"></activity>
<activity
android:screenOrientation="portrait"
android:name="LoginActivity"></activity>
<activity
android:screenOrientation="portrait"
android:name="SignupActivity"></activity>
<activity
android:screenOrientation="portrait"
android:name="MainMenuActivity"></activity>
<activity
android:screenOrientation="portrait"
android:name="InfoActivity"></activity>
<activity
android:screenOrientation="portrait"
android:name="ViewScoreActivity"></activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>
</application>
<uses-sdk
android:minSdkVersion="7"
/>
</manifest>
error is showing in line
android:installLocation="auto"
Thanks
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
. . .
</manifest>
Introduced in: API Level 8.
Backward Compatibility
The ability for your application to install on the external storage is a feature available only on devices running API Level 8 (Android 2.2) or greater. Existing applications that were built prior to API Level 8 will always install on the internal storage and cannot be moved to the external storage (even on devices with API Level 8). However, if your application is designed to support an API Level lower than 8, you can choose to support this feature for devices with API Level 8 or greater and still be compatible with devices using an API Level lower than 8.
To allow installation on external storage and remain compatible with versions lower than API Level 8:
Include the android:installLocation attribute with a value of "auto" or "preferExternal" in the element.
Leave your android:minSdkVersion attribute as is (something less than "8") and be certain that your application code uses only APIs compatible with that level.
In order to compile your application, change your build target to API Level 8. This is necessary because older Android libraries don't understand the android:installLocation attribute and will not compile your application when it's present.
When your application is installed on a device with an API Level lower than 8, the android:installLocation attribute is ignored and the application is installed on the internal storage.
Caution: Although XML markup such as this will be ignored by older platforms, you must be careful not to use programming APIs introduced in API Level 8 while your minSdkVersion is less than "8", unless you perform the work necessary to provide backward compatibility in your code. For information about building backward compatibility in your application code, see the Backward Compatibility article.
==>
go to eclipse project settings -> SEction "Android" and select at least API Level 8 there.
referenced by user "user370305" as comment:
change your application's api version from properties make it 8 or greater. then its work fine. Look at my edited answer. – user370305 Oct 13 '11 at 8:06
thx && good luck!
:=)

Categories

Resources