Android Studio 3.0 Compile Issue (Cannot choose between Configurations)

Solution 1:

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.

Solution 2:

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

Solution 3:

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.

Solution 4:

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