9

Mam problemy z przeniesieniem mojego projektu do najnowszej wersji Gradle 4.0 + Android Studio 3, co powoduje różnego rodzaju błędy. Stopniowo udało mi się je wszystkie uporządkować, z wyjątkiem tego.Android Studio 3 + Gradle 4.0 + shrinkResources + libraryProject = Nie można znaleźć pasującej konfiguracji w projekcie

Could not resolve all dependencies for configuration ':app:forGoogleCoverageRuntimeClasspath'. 
    > Unable to find a matching configuration in project :mylibrary: 
     - Configuration 'debugApiElements': 
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'. 
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=debug}'. 
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required. 
      - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'. 
      - Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided. 
     - Configuration 'debugRuntimeElements': 
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'. 
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=debug}'. 
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required. 
      - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'. 
      - Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided. 
     - Configuration 'releaseApiElements': 
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'. 
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=release}'. 
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required. 
      - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'. 
      - Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided. 
     - Configuration 'releaseRuntimeElements': 
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'. 
      - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=release}'. 
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required. 
      - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'. 
      - Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided. 

W celu paznokci w dół problemu:

  1. Utworzyłem minimalną projekt aplikacji z Android Studios asystent projektu
  2. dodany pusty moduł biblioteki które następnie dodać do moich zależnościami aplikacji .
  3. dodany jeden flavorDimensions i 2 productFlavors
  4. dodano 3 typy kompilacji i niech jeden typ kompilacji dziedziczyć z innej
  5. niech dziedziczone typu build umożliwić shrinkResources

Ostatnim krokiem produkuje wspomniany błąd, który jest podobny do tego pytania: Gradle 4.0 Unable to find a matching configuration

Ma ktoś pomysł, co jest tutaj, lub rozwiązanie tego problemu? Złożę też raport o błędzie.

mój pełny plik Gradle:

apply plugin: 'com.android.application' 

apply plugin: 'kotlin-android' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "gradletest.test" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    flavorDimensions "store" 

    productFlavors { 
     forAmazon { 
      dimension "store" 
     } 

     forGoogle { 
      dimension "store" 
     } 
    } 

    buildTypes { 

     debug { 
      debuggable true 
      minifyEnabled false 
     } 

     release { 
      minifyEnabled true 
      debuggable false 
      shrinkResources true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 

     coverage.initWith(buildTypes.debug) 
     coverage { 
      testCoverageEnabled true 
      minifyEnabled true 
      shrinkResources true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 


} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 

    implementation project(':mylibrary') 
} 
+0

Bug pod adresem: https://issuetracker.google.com/issues/62170415 poczuj się gwiazdą. Na razie pomaga mi usunąć shrinkResources z mojego typu kompilacji – JimmyVanBraun

Odpowiedz

6

Możliwa Rozwiązaniem jest stworzenie we wszystkich modułach brakujących buildTypes, ale to szaleństwo kod Messing kiedy Google strugane stworzyć sollution dla niego. Więcej informacji w: https://issuetracker.google.com/issues/62170415 jak ja (ale usunięty przez moderatora) i wspomnieć.

Ale jest drugi (ten sam, ale znacznie czystsze) rozwiązanie: dodać do swojej górnej projektu build.gradle

subprojects { 
    afterEvaluate {project -> 
     if (project.hasProperty("android")) { 
      android { 
       buildTypes { 
        YOUR_MISSING_BUILD_TYPES { 
         BUILD_TYPE_PARAMS_OR_EMPTY 
        } 
       } 
      } 
     } 
    } 
} 

EDIT: 2017-07-12

To ostatecznie ustalona classpath 'com.android.tools.build:gradle:3.0.0-alpha6'. Można użyć nowego DSL: https://issuetracker.google.com/issues/62241369

android { 
    buildTypeMatching 'staging', 'debug' 
    productFlavorMatching 'color', 'blue', 'cyan' 
} 

Czy nie zapomniał usunąć powyżej obejście przed build!

EDIT: 2017-07-18

Jest oficjalna dokumentacja: https://issuetracker.google.com/issues/62241369

Aby rozwiązać ten problem, należy określić, który typ budowy z "MyLibrary" plugin Android powinien być zgodny z typem kompilacji aplikacji "inscenizacja" aplikacji. Możesz to zrobić za pomocą właściwości buildTypeMatching w kompilacji aplikacji .Gradle pliku, w sposób pokazany poniżej:

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

Edycja: 2017-09-06

buildTypeMatching została usunięta z Beta 4.
teraz użyć matchingFallbacks.
patrz: https://stackoverflow.com/a/46038946/4594990

+0

W moim projekcie typy kompilacji w module aplikacji i module lib to "debugowanie" i "wydanie". Próbowałem wstawiać buildTypeMatching "debugowanie", "wydanie" w app build.gradle. Wciąż generuje ten sam błąd https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#buildTypeMatching – DroidLearner

+0

Oto mój typ kompilacji dla aplikacji i biblioteki https: // gist .github.com/anonymous/1dda4a85d4d3c021a8fc07251901f9f2 – DroidLearner

+1

buildTypeMatching został usunięty. https://stackoverflow.com/a/46038946/4594990 – vigilancer

0

Możliwa duplikat Gradle 4.0 Unable to find a matching configuration

Sprawdź, czy masz dokładną liczbę konfiguracji budowlanej (buildTypes) we wszystkich modułach.

W mojej wstępnej konfiguracji 3.0, miałem tylko debug {} i uwolnienie {} we wszystkich moich com.android.library modułów. Dodałem jeszcze jedną konfigurację podobną do tej z: modułu aplikacji. Wszystko dla mnie dobrze.

+0

Twój sposób działania, pracował w Canary 4 i 6. W Canary 7 i Canary 8, nadal generuje błąd – DroidLearner

+0

Oto mój typ kompilacji dla aplikacji i bibliotek https: //gist.github.com/anonymous/1dda4a85d4d3c021a8fc07251901f9f2 – DroidLearner

3

JEŚLI twoja aplikacja zawiera typ kompilacji, którego nie ma zależność od biblioteki.

Na przykład Twoja aplikacja zawiera typ kompilacji "przemieszczania", ale zależność obejmuje tylko typ kompilacji "debugowanie" i "wydanie".

Dostaniesz błąd jak

Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve project :library. Open File Show Details

Można rozwiązać ten problem poprzez dodanie

buildTypes { 
     staging { 
      proguardFile getDefaultDexGuardFile('dexguard-release.pro') 
      proguardFile 'dexguard-rules.pro' 
      matchingFallbacks = ['debug', 'release'] //add this line 
     } 
    } 

błędy Resolve kompilacji związanych z zależnościami dopasowanie raportu official docs

Powiązane problemy