Android Studio Lint - set API level for lint

That's what. I have an application compatible with API 15 and above, but since it is quite large and I have already reached the limit of 65k, I had to make it a descendant of the MultiDexApplication class. This slows down the build time a bit, so I had to implement some optimizations to speed up the process. I have the following code in my manifest that significantly reduces build time when building API> = 21 (taken from some other SO thread):

productFlavors { dev { minSdkVersion 21 } prod { minSdkVersion 15 } } 

Everything works fine, but the problem is that during development Android studio thinks that my SDS miniSdkVersion level is 21 (correct) and lint does not show me the incompatible API (15-21). I really want to be able to build using minSdkVersion set to 21 (quick build), but set "lint minSdkVersion" to 15, so I see parts of the code that are not compatible with the old API than 21. I tried to do this, and also look at AS lint preferences, but I did not find anything useful. Thanks for any suggestions. My current solution is to switch minSdkVersion in the dev flavor to 21 and check if there is any error, but that is not quite what I want.

+5
source share
1 answer

This question answers your question. It shows how to build a project with any minimum SDK, while maintaining a minimum SDK for Lint alerts.

To summarize the message, you can dynamically calculate the minSdkVersion value:

 int minSdk = hasProperty('devMinSdk') ? devMinSdk.toInteger() : 15 apply plugin: 'com.android.application' android { ... defaultConfig { minSdkVersion minSdk ... } } 

In this example, we check if the devMinSdk property is devMinSdk , and if true, we use it. Otherwise, we will be 15 by default.

How to pass devMinSdk value for build script? Two options:

Using the command line:

 ./gradlew installDebug -PdevMinSdk=21 

Using Android Studio settings:

Go to the "Settings" section in Windows) → "Build, -PdevMinSdk=21 , Deploy → Compiler → put -PdevMinSdk=21 in the" Command Line Parameters text box.

Android Studio Compiler Options

+6
source

All Articles