web-dev-qa-db-fra.com

Problème de compilation avec Android Studio 3.0 (impossible de choisir entre les configurations)

Problème avec la dernière version 3.0 (version bêta 2) Mon projet a 1 sous-module créé par une tierce partie, je n'ai donc accès qu'à leur build.gradle.

Mon projet a 3 saveurs, snap, uat, production. Chacun a 2 types de construction, debug et release. Quand j'essaie de construire, je reçois ceci.

Error:Cannot choose between the following configurations of project :lp_messaging_sdk:
  - debugApiElements
  - debugRuntimeElements
  - releaseApiElements
  - releaseRuntimeElements
All of them match the consumer attributes:
  - Configuration 'debugApiElements':
      - Found com.Android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'Java-api' but wasn't required.
  - Configuration 'debugRuntimeElements':
      - Found com.Android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'Java-runtime' but wasn't required.
  - Configuration 'releaseApiElements':
      - Found com.Android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'Java-api' but wasn't required.
  - Configuration 'releaseRuntimeElements':
      - Found com.Android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.Android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'Java-runtime' but wasn't required.

J'ai lu qu'il y avait des problèmes avec les sous-modules et les types de construction, mais j'ai lu que c'était réparé . 

buildTypeMatching  'debug', 'release'

Quand je fais cela cependant, je reçois cette erreur,

Error:Could not select value from candidates [debug, release] using AlternateDisambiguationRule.BuildTypeRule.

apply plugin: 'com.Android.application'

Android {

    repositories {
        flatDir {
            dirs project(':lp_messaging_sdk').file('aars')
        }
    }

    // Android parameters
    compileSdkVersion = 26
    buildToolsVersion = '26.0.1'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        preDexLibraries true
    }

    defaultConfig {
        minSdkVersion 19
        versionName buildName
        versionCode buildVersion
        multiDexEnabled true
        resConfigs "en", "fr", "fr-rCA"
    }

    signingConfigs {
        release {

        }
    }

    flavorDimensions "default"

    productFlavors {
        snap {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionReleaseNotesFilePath = 'changelog.txt'
            ext.betaDistributionNotifications = true
            dimension "default"
        }

        uat {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionNotifications = true
        }

        production {
        }
    }

    buildTypes {
        debug {
            versionNameSuffix createVersionNameSuffix()
            applicationIdSuffix '.debug'
            minifyEnabled true
            testCoverageEnabled false
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/Android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
            ext.enableCrashlytics = false
        }

        release {
            versionNameSuffix createVersionNameSuffix()
            minifyEnabled true
            testCoverageEnabled = false
            signingConfig signingConfigs.release
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/Android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
        }

    }

    //Used to ignore duplicated entries added to meta-inf
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    dexOptions {
        javaMaxHeapSize "2048m"
        dexInProcess true
    }

    lintOptions {
        abortOnError true
        xmlReport true
        htmlReport true
        disable 'MissingTranslation', 'InvalidPackage'
        disable 'GradleCompatible', 'GradleCompatible'
        disable 'NewApi', 'NewApi'
        disable 'GradleDependency'
        disable 'UnusedResources'
        disable 'IconDensities'
        disable 'TypographyDashes'
        disable 'ContentDescription'
        htmlOutput file("$project.buildDir/reports/lint/lint-result.html")
        xmlOutput file("$project.buildDir/reports/lint/lint-result.xml")
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

greendao {
    schemaVersion 13
    targetGenDir 'src/main/Java/'
}

ext.betaDistributionReleaseNotes = System.getenv("CHANGELOG")

def createVersionNameSuffix() {
    def buildNumber = System.env.BUILD_NUMBER
    def buildTimestamp = new Date().format('HH:mm dd/MM/yy')
    return buildNumber ? " ($buildNumber)" : " ($buildTimestamp)"
}

def getBuildVersionFromName(String buildName) {
    List data = buildName.tokenize(".")
    String resultString = "19";

    for (String s : data) {
        resultString += s;
    }

    if (System.env.BUILD_NUMBER) {
        resultString += System.env.BUILD_NUMBER
    }

    return Integer.parseInt(resultString);
}

//Verify the app before creating a Pull Request
task verifyPR
verifyPR.dependsOn('clean')
verifyPR.dependsOn('lint')
verifyPR.dependsOn('checkstyle')
verifyPR.dependsOn('pmd')
verifyPR.dependsOn('testSnapDebugUnitTest')

dependencies {
    // Android Dependencies
    compile 'com.Android.support:appcompat-v7:26.0.1'
    compile 'com.Android.support:design:26.0.1'
    compile 'com.Android.support:recyclerview-v7:26.0.1'
    compile 'com.Android.support:multidex:1.0.2'

    // Dagger Dependencies
    apt 'com.google.dagger:dagger-compiler:2.11'
    compile 'org.glassfish:javax.annotation:10.0-b28'
    compile 'com.google.dagger:dagger:2.11'

    // Rx Dependencies
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.3.0'
    compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.4.0'
    compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
    compile 'com.squareup.whorlwind:whorlwind:1.0.1'
    compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar'
    compile 'com.jenzz:RxAppState:2.0.0'

    // Tools
    compile 'com.crashlytics.sdk.Android:crashlytics:2.6.5'

    // ButterKnife
    compile 'com.jakewharton:butterknife:8.4.0'

    // Google Maps
    compile 'com.google.Android.gms:play-services-maps:11.0.4'
    compile "com.google.Android.gms:play-services-analytics:11.0.4"
    compile 'com.google.Android.gms:play-services-location:11.0.4'
    compile 'com.google.Android.gms:play-services-places:11.0.4'
    compile 'com.google.Android.gms:play-services-gcm:11.0.4'

    // Geofence
    compile('pl.charmas.Android:android-reactive-location:0.10@aar') {
        transitive = true
    }

    // Retrofit
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'

    // OKHTTP
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'

    // Libphonenumber
    compile 'com.googlecode.libphonenumber:libphonenumber:7.3.2'

    // UI
    compile 'com.tubb.smrv:swipemenu-recyclerview:5.0.2'

    // EventBus
    compile 'org.greenrobot:eventbus:3.0.0'

    // Database
    compile 'org.greenrobot:greendao:3.2.0'

    // Chuck HTTP Inspector
    debugCompile 'com.readystatesoftware.chuck:library:1.0.4'
    releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.0.4'

    // ViewPager Indicator
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'

    // Amplitude
    compile 'com.amplitude:Android-sdk:2.13.2'

    // TESTS
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.10.19"
    testCompile "org.powermock:powermock-module-junit4:1.6.5"
    testCompile "org.powermock:powermock-module-junit4-rule:1.6.4"
    testCompile "org.powermock:powermock-api-mockito:1.6.5"
    testCompile "org.powermock:powermock-classloading-xstream:1.6.4"

    compile project(':lp_messaging_sdk')
}

Et voici la bibliothèque tierce build.gradle

apply plugin: 'com.Android.library'

Android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 250
        versionName "2.5.0"
    }

    flavorDimensions "default"

    productFlavors {
        snap {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionReleaseNotesFilePath = 'changelog.txt'
            ext.betaDistributionNotifications = true
            dimension "default"
        }

        uat {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionNotifications = true
        }

        production {

        }
    }

    signingConfigs {
        release {

        }
    }

    buildTypeMatching 'snap', 'debug', 'release'

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            minifyEnabled true
            testCoverageEnabled false
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/Android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
            ext.enableCrashlytics = false
        }

        release {
            minifyEnabled true
            testCoverageEnabled = false
            signingConfig signingConfigs.release
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/Android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
        }
    }

    defaultConfig {
        consumerProguardFiles 'proguard.cfg'
    }

    repositories {
        flatDir {
            dirs 'aars'
        }
    }

    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    compile 'com.Android.support:appcompat-v7:26.0.1'
    compile 'com.Android.support:design:26.0.1'
    compile 'com.Android.support:recyclerview-v7:26.0.1'
    compile 'com.Android.support:percent:26.0.1'
    compile 'com.Android.support.constraint:constraint-layout:1.0.2'

    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.neovisionaries:nv-websocket-client:1.31'
    compile 'com.squareup.okhttp3:okhttp:3.8.0'

    compile(name: 'infra', ext: 'aar')
    compile(name: 'messaging', ext: 'aar')
    compile(name: 'messaging_ui', ext: 'aar')
    compile(name: 'ui', ext: 'aar')
}

Est-ce que quelqu'un sait comment je peux résoudre ce problème? Merci

55
AndyOHart

Erreur: impossible de choisir entre les configurations de projet suivantes .......

Il peut y avoir des problèmes d’écriture graduelle Lorsque je suis passé au libellé suivant, il n’ya pas d’erreur de ce type.

// compiler le projet (': MPChartLib')

implementation project(':MPChartLib')

Peut-être que lorsque la référence dépend d'autres modules devrait être écrit dans cette implémentation

13
MyDesire

Si vous utilisez le plug-in Android-apt pour le traitement des annotations, essayez de supprimer ce plug-in et de remplacer toutes les références apt some_dependency par annotationProcessor some_dependency comme suggéré dans le guide de migration du plugin Android Gradle 3.0.0 .

11
Matt

Lorsque j’ai mis à jour mon projet du niveau 23 à 27 de l’API et de la graduation à 3,1, cette erreur est arrivée. 

"Impossible de choisir entre différentes configurations".

Donc, pour résoudre ce problème.

remplace le projet compile (': votre nom de projet')

avec projet d'implémentation (': nom du projet')  

en ordre cela résoud le problème.

2
justchill

Dans mon cas similaire, la solution était la suivante:

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')
}

Peut-être que cela aide les autres à se retrouver ici avec un problème similaire.

0
hb0

pour AndroidStudio 3.0+, mainMoudle a buildTypes et buildTypes identiques à libModule buildTypes et buildTypes, il aimerait:

module principal:

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{

    }
}

ou vous pouvez utiliser matchingFallbacks résoudre ce problème cliquer

0
Jack Deng

Mon problème était le fait que je renommais le nom du fichier de sortie (et son chemin)

Une fois que j'ai supprimé le code qui changeait le nom de la solution, le chemin vers ma solution était plus simple.

0
TacB0sS