APK errors

minSdkVersion conflict

Error text

uses-sdk:minSdkVersion 21 cannot be smaller than version 24 declared in library [com.example:lib:2.0]
Suggestion: use a compatible library with a minSdk of at most 21

Cause

A library needs a newer Android than your app allows. The app's minSdk is lower than the library's.

Step-by-step fix

  1. Read which library asks for which number.
  2. If you can drop old phones, raise your minSdk to that number.
  3. If you cannot, pick an older version of the library or an alternative.
  4. Last resort: tools:overrideLibrary="com.example.lib" in the manifest. It may crash on old phones, so test first.
  5. After the change open the app on an emulator with the old version.

Example commands

android { defaultConfig { minSdk = 24 } }
./gradlew :app:processDebugManifest --stacktrace
./gradlew :app:dependencyInsight --dependency lib --configuration debugRuntimeClasspath

How to prevent it

Choose minSdk by looking at market share, and check it for every new library.

Author and license: Nibras Code