Android Studio 3.0 Error. Migrate dependency configurations for local modules

前端 未结 6 483
南方客
南方客 2020-12-07 17:47

I recently installed the latest Canary build of Android Studio which is currently using the Android Gradle plugin 3.0.0-alpha4 .

I now get a error:

E         


        
6条回答
  •  甜味超标
    2020-12-07 17:57

    With the new plugin, the variant-aware dependency resolution

    implementation project(':MyLib')
    

    needs to have exact matching build types. The migration guide describes this

    For instance, it is not possible to make a 'debug' variant consume a 'release' variant through this mechanism because the producer and consumer would not match. (In this case, the name 'debug' refers to the published configuration object mentioned above in the Publishing Dependencies section.) Now that we publish two configurations, one for compiling and one for runtime, this old way of selecting one configuration really doesn't work anymore.

    So the old method of

    releaseCompile project(path: ':foo', configuration: 'debug')
    

    will not work anymore.

    Example

    With your example this would look like this:

    In app build.gradle:

    apply plugin: 'com.android.application'
    
    android {
      buildTypes {
        debug {}
        releaseApp {}
        releaseSdk {}
      }
      ...
      dependencies {
        implementation project(':MyLib')
      }
    }
    

    In module/lib 'MyLib' build.gradle:

    apply plugin: 'com.android.library'
    
    android {
      buildTypes {
        debug {}
        releaseApp {}
        releaseSdk {}
      }
    }
    

    Therefore the build type must exactly match, no more no less.

    Using Build-Type Fallbacks

    A new feature called "matchingFallbacks" can be used to define default buildtypes if a sub-module does not define the buildtype.

    Use matchingFallbacks to specify alternative matches for a given build type (...)

    For example if module/lib 'MyLib' gradle would look like this:

    apply plugin: 'com.android.library'
    
    android {
      buildTypes {
        debug {}
        releaseLib {}
      }
    }
    

    You could define the following in your app build.gradle:

    apply plugin: 'com.android.application'
    
    android {
      buildTypes {
        debug {}
        releaseApp {
            ...
            matchingFallbacks = ['releaseLib']
        }
        releaseSdk {
            ...
            matchingFallbacks = ['releaseLib']
        }
      }
      ...
      dependencies {
        implementation project(':MyLib')
      }
    }
    

    Missing Flavor Dimensions

    Use missingDimensionStrategy in the defaultConfig block to specify the default flavor the plugin should select from each missing dimension

    android {
        defaultConfig {
            missingDimensionStrategy 'minApi', 'minApi18', 'minApi23'
            ...
        }
    }
    

提交回复
热议问题