Jafar Sadiq SH
Jafar Sadiq SH

Reputation: 734

Androidx Camera: Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21

Hi I am using CameraX api to build custom camera, after adding updated library dependency to build.gradle file, i am getting following build error


Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [androidx.camera:camera-extensions:1.0.0-alpha08] /Users/.gradle/caches/transforms-2/files-2.1/f20dc98c605a4c4dbd6030601f9665d3/camera-extensions-1.0.0-alpha08/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="androidx.camera.extensions" to force usage (may lead to runtime failures)


build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
        compileSdkVersion 29
        buildToolsVersion "29.0.3"

        defaultConfig {
                    applicationId ""
                    minSdkVersion 16
                    targetSdkVersion 29
                    versionCode 1
                    versionName "1.0"
                    multiDexEnabled true
                    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
                    vectorDrawables.useSupportLibrary = true
            }

            buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                    }
            }

            compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
            }

            dataBinding {
                    enabled = true
            }

            flavorDimensions 'dimensions'

            productFlavors {

                    dev {
                        //assembleDevDebug crashlyticsUploadDistributionDevDebug
                        applicationId ""
                        versionName "D(0.0)"   //for QA Release
                        versionCode 00
                        proguardFile("proguard-rules.pro")
                    }

                    prod {
                        applicationId ""
                        versionName "1.3" //for prod release
                        versionCode 13
                        proguardFile("proguard-rules.pro")
                        resValue "string", "app_name", "Prod Android"
                    }
            }

    }

dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "androidx.camera:camera-core:1.0.0-beta01"
        implementation "androidx.camera:camera-camera2:1.0.0-beta01"
        implementation "androidx.camera:camera-extensions:1.0.0-alpha08"

}
apply plugin: 'com.google.gms.google-services'

Upvotes: 4

Views: 3346

Answers (2)

Adekola Akano
Adekola Akano

Reputation: 169

You can stick to your minimum version 16 by adding the following to your manifest file.

<uses-sdk tools:overrideLibrary="androidx.camera.view, androidx.camera.camera2, androidx.camera.lifecycle, androidx.camera.core"/>

To avoid runtime failures you'll need to check if the device is running on api 21 and above before using CameraX

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        // Use camera2 or cameraX
}else{
        // Use Camera1
}

Upvotes: 11

Waqar UlHaq
Waqar UlHaq

Reputation: 6422

Update your app.gradle minSdkVersion

from:

 minSdkVersion 16

to:

minSdkVersion 21

Upvotes: 4

Related Questions