简体   繁体   中英

Android Manifest: Can't force minSDK anymore. “should not be declared in the android manifest file”

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

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. (eg 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!

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'
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM