0

Got a little build issue.

Got a lib that requires minSDK:23 while I still want to support 21.

The solution of

    <uses-sdk
    android:minSdkVersion="21"
    tools:overrideLibrary="a.rogue.library" />

Doesn't sync anymore and shows

The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file. Remove minSdkVersion and sync project Affected Modules: approot

Strange observation: Sync fails but Build succeeds. Moreover, sync after build succeeds, too.

It's an unhealthy situation, though:

  • If I add the overrideLibrary line to the manifest - it won't sync.
  • If I remove the overrideLibrary line from the manifest - it won't build, of course, because there is a minSDK conflict.

Any way to settle this out? Can overrideLibrary reside somehow in the build.gradle?

Thanks

Maneki Neko
  • 1,177
  • 1
  • 14
  • 24
  • I think you are importing the old project, am I right? – iamkdblue Jun 04 '20 at 04:10
  • No, my app was built in Gradle from scratch. I want to import an aar, but that aar forces me to stop supporting 21,22, which I'd rather not do :-( – Maneki Neko Jun 04 '20 at 04:13
  • did you add minSdkVersion 21 in gradle? – iamkdblue Jun 04 '20 at 04:16
  • Of course. That's the reason for the conflict. You know, Manifest merger tries to decide what version to put in the final manifest. The root module min SDK is smaller than the lib's SDK => You request the app to support a version that's not supported by your SDKs. If it puts the max, it "disobeys" your minSDK request. If it forces the min - your app may break in runtime and you won't even know it. It's a conflict! By the way, the opposite direction works because the libs automatically support API levels greater than their minimum. – Maneki Neko Jun 04 '20 at 04:54

2 Answers2

1

I also bumped into this today, and as far as I see it has been introduced as part of version 4.0.0 of the Android Gradle Plugin (I'm still searching for reference) and while it looks frustrating at first I think is the right thing to do as it actually avoids some potential runtime crashes. (e.g. when a consumer calls into an API of the library which relies on some other API that has been introduced in a newer SDK version but we've forced it to be older anyway)

If you can afford just go back to the previous stable version 3.6.3 and you'll be fine for now, but the library developers chose the minimumSdkVersion for a reason. Maybe reach out to them to clarify the rationale behind it and get some advise. Good luck!

Zsolt Boldizsar
  • 2,447
  • 2
  • 27
  • 37
0

I just did this and it worked. In the app-level build.gradle file just make sure you specify 'minSdkVersion #' in the defaultConfig section where the # sign mentioned previously is the SDK number you are targeting. Example:

android {
compileSdkVersion 30
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.ranchhand1"
    minSdkVersion 23
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

Will Buffington
  • 1,048
  • 11
  • 13