Here is the thing. I have an app that is compatible with API 15 and above, but since it's pretty big and I've already hit a 65k methods limit, I had to make it a descendant of MultiDexApplication class. This slows down the build times a bit, so I had to implement some optimization to speed up the process. I have the following code in my manifest, which significantly reduce build times when building for API >= 21 (taken from some other SO thread):
productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 15
}
}
Everything is working perfectly, but the problem is that during the development, Android studio thinks that my minSdkVersion SDK level is 21 (correctly), and the lint does not show me incompatible API (15-21). What I really want is to be able to build with minSdkVersion set to 21 (fast build), but set the "lint minSdkVersion" to 15, so I see the parts of the code that are not compatible with older API than 21. I tried to google it and also to look into AS lint preferences but I didn't find anything useful. Thanks for any suggestions. My current solution is to switch minSdkVersion in dev flavor to 21 and check if there's any error, but this is not really what I want.
Integrating In An Existing Codebase¶ Luckily, Android Lint makes it easy to start using lint by providing a baseline. A baseline lets you take a snapshot of your project and then uses the snapshot as a baseline for future inspection runs. To create a baseline add the following in your build. gradle file.
lintOptions { abortOnError false } This means it will run lint checks but won't abort the build if any lint error found. By default, its true and stops the build if errors are found.
Run lint using the standalone tool If you're not using Android Studio or Gradle, you can use the standalone lint tool after you install the Android SDK Command-Line Tools from the SDK Manager. You can then locate the lint tool at android_sdk /cmdline-tools/ version /bin/lint .
In many cases, lint warns you about incorrect, error-prone, or nonstandard code that the compiler does not necessarily flag. The lint program issues every error and warning message produced by the C compiler.
This gist answers your question. It shows how to build the project with whatever dev minimum SDK value, while maintaining production minimum SDK value for Lint warnings.
To summarize the post, 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're checking if devMinSdk
property defined, and if true - we're using it. Otherwise, we default to 15.
How do we pass devMinSdk
value to build script? Two options:
Using command line:
./gradlew installDebug -PdevMinSdk=21
Using Android Studio preferences:
Go to Preferences (Settings on Windows) -> Build, Execution, Deployment -> Compiler -> put -PdevMinSdk=21
in Command-line Options text box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With