Android Studio 3.0 Error. Migrate dependency configurations for local modules

前端 未结 6 454
南方客
南方客 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'
            ...
        }
    }
    
    0 讨论(0)
  • 2020-12-07 18:04

    Today I also had the same problem after migrating to Android Studio 3. The problem is the gradle is not able to resolve the certain libraries due to network issue. The reasons might be various. If you work behind the proxy you need to add the proxy parameters in gradle.properties file:

    systemProp.http.proxyHost=<proxy_host>
    systemProp.http.proxyPort=<proxy_port
    systemProp.https.proxyHost=<proxy_host>
    systemProp.https.proxyPort=<proxy_port>
    

    In my case I had one more issue. My company uses the self signed SSL certificate so the SSL connection had some problem. If same applies also for you, you can set the parameter again in gradle.properties file as follows:

    org.gradle.jvmargs=-Djavax.net.ssl.trustStore="/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStorePassword=changeit
    

    To be more clear you can click on "Show details" link in messages log in Android Studio. This log will be more helpful to decide what is the real problem.

    0 讨论(0)
  • I was facing the same problem, I found this migration page: Build matching types

    It states:

    Select defaults for missing build types
    If a consumer configures a build type that a producer does not, you need to manually match the consumer's build type to one from the producer. For example, if your app module configures a "staging" build type and its library module dependency, "mylibrary", does not, the Android plugin throws the following build error:

    Error:Failed to resolve: Could not resolve project :mylibrary.
    Required by: project :app
    

    To resolve this error, you need to specify which build type from "mylibrary" the Android plugin should match to the app's "staging" build type. You can do this with the buildTypeMatching property in the app's build.gradle file, as shown below:

    // Add the following to the consumer's build.gradle file.
    android {
        ...
        // Tells the Android plugin to use a library's 'debug' build type
        // when a 'staging' build type is not available. You can include
        // additional build types, and the plugin matches 'staging' to the
        // first build type it finds from the one's you specify. That is,
        // if 'mylibrary' doesn't include a 'debug' build type either, the
        // plugin matches 'staging' with the producer's 'release' build type.
        buildTypeMatching 'staging', 'debug', 'release'
    }
    

    Adding buildTypeMatching fixed it for me without creating unecessary types in my library

    0 讨论(0)
  • 2020-12-07 18:09

    This solution worked for me. I'm using Android Studio 3.1.2. Android Gradle plugin 3.1.2. Gradle 4.4. I have a library module with flavours such as trial and premium. As part of the process of migrating to the Android Gradle plugin 3.1.2 I added a flavour dimension of main to my library module's gradle build file. To correct the build error therefore in my app's build.gradle file I changed the following:

    debugImplementation project(path: ':library', configuration: 'premiumDebug')
    releaseImplementation project(path: ':library', configuration: 'premiumRelease')
    

    became

    implementation project(':library')
    

    and I added the following line to my defaultConfig block: missingDimensionStrategy 'main', 'premium'

    0 讨论(0)
  • 2020-12-07 18:13

    After facing the same issue, I finally declared exactly the same buildTypes in both App and Modules' build.gradle files.

    In your case, adding

    buildTypes {
        debug {}
        releaseApp {}
        releaseSdk {}
    }
    

    to your module's build.gradle should do the trick.

    Be sure to change any "compile project" to "implementation project" too.

    Hope it helps

    0 讨论(0)
  • 2020-12-07 18:15

    Google added more instruction how to solve it: Resolve build errors related to dependency matching

    Cause of build error:

    Your app includes a build type that a library dependency does not.

    For example, your app includes a "staging" build type, but a dependency includes only a "debug" and "release" build type.

    Note that there is no issue when a library dependency includes a build type that your app does not. That's because the plugin simply never requests that build type from the dependency.

    Resolution

    Use matchingFallbacks to specify alternative matches for a given build type, as shown below:

    // In the app's build.gradle file.
    android {
        buildTypes {
            debug {}
            release {}
            staging {
                // Specifies a sorted list of fallback build types that the
                // plugin should try to use when a dependency does not include a
                // "staging" build type. You may specify as many fallbacks as you
                // like, and the plugin selects the first build type that's
                // available in the dependency.
                matchingFallbacks = ['debug', 'qa', 'release']
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题