Skip to content

[Solved][Flutter] Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera]

Last Updated on 2021-10-19 by Clay

In the official teaching document on how to use the camera in Flutter, it is mentioned that if the camera is called through Flutter in the Android system, the minimum SDK version must be higher than 21.

If lower, the following error will occur (that is the problem I encountered today):

Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/clay/Projects/FlutterProjects/flutter_medication_reminder/build/camera/intermediates/library_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 16
  	Suggestion: use a compatible library with a minSdk of at most 16,
  		or increase this project's minSdk version to at least 21,
  		or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)

Solution

To solve this problem, we must modify the minimum SDK version of Android in the Flutter project.

In the Flutter project, the file path we want to modify is PROJECT_NAME/android/app/build.gradle. The file should have the following content:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.clayatlas.flutter_project"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}



It can be found that the current minSdkVersion is 16, which is consistent with the error message provided. If should be changed to 21 or the higher version you need .

After I adjusting the minimum version, I was able to successfully execute the program that calls the camera in the Flutter project.


References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version