Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the usage of tools:targetApi="m"?

Tags:

I have an app uses clearText between Android-client and server using Retrofit, and in Android 9+ it's not allowed to use clearText.

To ignore that I added android:usesCleartextTraffic="true" in Manifest but it warns: tools:ignore="GoogleAppIndexingWarning" and suggests to add tools:targetApi="m".

It's a bit confusing:

  • Is the tools:targetApi="m" means that any attributes with tools: is for Marshmallow and higher?

  • Is it for using this version of Manifest or something else? Is this making unwanted mistake in my app?

My Manifest:

... <application     android:name=".ApplicationClass"     android:allowBackup="true"     android:fullBackupContent="false"     android:hardwareAccelerated="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:supportsRtl="false"     android:theme="@style/AppTheme.NoActionBar"     android:usesCleartextTraffic="true"     tools:ignore="GoogleAppIndexingWarning"     tools:targetApi="m">     ... 
like image 555
Mahdi Moqadasi Avatar asked Apr 14 '19 10:04

Mahdi Moqadasi


People also ask

What is Tools TargetApi?

By adding tools:targetApi="m" to an element you tell the lint that the element won't be used on API level below 23 (M). See the attribute documentation. This tells the tools that you believe this element (and any children) will be used only on the specified API level or higher.

What is TargetApi?

public abstract @interface TargetApi. implements Annotation. android.annotation.TargetApi. Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is.


1 Answers

From the docs you can read:

Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is

This means it will affect only the annotated one.

Other attributes with tools won't be affected. tools is a namespace, from which you can get attributes, an attribute won't affect the entire namespace.

like image 200
Luca Nicoletti Avatar answered Sep 19 '22 15:09

Luca Nicoletti