Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.0 Compile Issue (Cannot choose between Configurations)

People also ask

What is missingDimensionStrategy?

missingDimensionStrategy(dimension: String, requestedValue: String) Specifies a flavor that the plugin should try to use from a given dimension in a dependency.

What is default config in Android Studio?

Specifies defaults for properties that the Android application plugin applies to all build variants. Specifies defaults for properties that the Android dynamic-feature plugin applies to all build variants. Specifies defaults for properties that the Android library plugin applies to all build variants.

What is build configuration in Android?

The Android build system compiles app resources and source code, and packages them into APKs or Android App Bundles that you can test, deploy, sign, and distribute.


Try

implementation project(path: ':lp_messaging_sdk', configuration: 'default')

Note:

You can avoid this bug by update gradle to 4.3 check this.

Explanation :

Using Dependency Configurations makes it easy to define and specify what to use in sub-project.

In my answer, we used default configuration and this will publish and expose only the "release" flavor to other Android projects and modules.

Assume you need to include this flavor only with demo flavor or with release flavor, it would be like :

configurations {
  // Initializes placeholder configurations that the Android plugin can use when targeting
  // the corresponding variant of the app.
  demoDebugCompile {}
  fullReleaseCompile {}
  ...
}
dependencies {
  // If the library configures multiple build variants using product flavors,
  // you must target one of the library's variants using its full configuration name.
  demoDebugCompile project(path: ':lp_messaging_sdk', configuration: 'demoDebug')
  fullReleaseCompile project(path: ':lp_messaging_sdk', configuration: 'fullRelease')
  ...
}

And so, in your case, you may use your build flavors, and that's what appeared in the error log.

Cannot choose between the following configurations of project :lp_messaging_sdk

And that's mean, that your lp_messaging_sdk have various build configurations:-

  - debugApiElements
  - debugRuntimeElements
  - releaseApiElements
  - releaseRuntimeElements

And android-studio telling you, that "I can't choose one configuration from these various, Would you define one for me?"

You can read more over here.


Error:Cannot choose between the following configurations of project.......

There may be gradle writing problems When I changed to the following wording there is no such error

// compile project(':MPChartLib')

implementation project(':MPChartLib')

Maybe when the reference depends on other modules should be written in this implementation


If you're using the android-apt plugin for annotation processing, try removing that plugin and replacing all of the apt some_dependency references with annotationProcessor some_dependency as suggested in the migration guide for the Android Gradle Plugin 3.0.0.


for AndroidStudio 3.0+, mainMoudle has buildTypes and buildTypes as same as libModule buildTypes and buildTypes ,it would like:

mainModule:

buildTypes {
    release {
        buildConfigField "boolean", "LOG_DEBUG", "false"
        zipAlignEnabled true
        shrinkResources true
        minifyEnabled true
        proguardFiles 'proguard-rules.pro'
    }

    debug {
        buildConfigField "boolean", "LOG_DEBUG", "true"
        zipAlignEnabled true
        shrinkResources false
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug2{

    }
}

libModule:

buildTypes {
    release {

    }

    debug {

    }

    debug2{

    }
}

or you can use matchingFallbacks solve this click


When I updated my project from API level 23 to 27 and Gradle to 3.1 this error comes that

Can not choose between different configuration

So to solve this problem.

replace the

compile project(':your projectName')

with

implementation project(':projectname')

in Gradle, this solves the problem.


In my, similar, case the solution was:

build.gradle:

android {
    defaultConfig {
        // because I have two project flavors in that library
        missingDimensionStrategy 'project', 'myProjectName' 
        // because I have a "full" and a "debug" flavor in that library
        missingDimensionStrategy 'mode', 'full'
    }
    buildTypes {
        debug { ... }
        release { ... }
    }
}
dependencies {
    // because the project(path:'', configuration:'') did not work in this case
    implementation project(':myModuleName1')
    implementation project(':myModuleName2')
}

Maybe this helps others ending up here with a similar problem.


For me, run into the same error on Android Studio 3.5.2, with a different cause. I was trying to add an application module as a library.

I resolved it by simply converting the application module to a library module .