Program Tip

Gradle : 둘 이상의 프로젝트 변형 : myLib이 소비자 속성과 일치합니다.

programtip 2020. 10. 5. 20:38
반응형

Gradle : 둘 이상의 프로젝트 변형 : myLib이 소비자 속성과 일치합니다.


내가 작성한 라이브러리 myLibRemoteMessage에서 사용 Firebase하며 앱 자체도 Firebase.

Gradle 사용 4.7. 또한 4.4.1에서 이것을 직면합니다.

그것을 고치는 방법?

project.gradle

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        mavenLocal()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    dexOptions {
        preDexLibraries = false
        jumboMode = false
        javaMaxHeapSize "2048M"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:27.1.1'

    implementation 'com.google.android.gms:play-services-gcm:12.0.1'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.firebase:firebase-core:12.0.1'
    implementation 'com.google.firebase:firebase-messaging:12.0.1'
    implementation 'com.google.firebase:firebase-crash:12.0.1'

    implementation project(":myLib")
}

apply plugin: 'com.google.gms.google-services'

myLib.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27



    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

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

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:27.1.1'

    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
    implementation 'com.j256.ormlite:ormlite-core:5.0'
    implementation 'com.j256.ormlite:ormlite-android:5.0'

    implementation 'com.google.firebase:firebase-messaging:12.0.1'
}

testApp\myLib> gradle clean assembleDebug에서 오류 출력testApp\app> gradle clean assembleDebug

두 개 이상의 project : myLib 변형이 소비자 속성과 일치합니다.

  • 구성 ': myLib : debugApiElements'변형 android-aidl :
    • artifactType 'android-aidl'을 찾았지만 필수는 아닙니다.
    • com.android.build.api.attributes.BuildTypeAttr 'debug'가 필요하며 호환되는 값 'debug'를 찾았습니다.
    • com.android.build.api.attributes.VariantAttr 'debug'를 찾았지만 필수는 아닙니다.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-classes:
    • Found artifactType 'android-classes' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-manifest:
    • Found artifactType 'android-manifest' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-renderscript:
    • Found artifactType 'android-renderscript' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant jar:
    • Found artifactType 'jar' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.

The google-services gradle plugin is made to work with Google Play Services and Firebase 15+, but you're using it with version 12.0.1.

The solution is to either:

  • Upgrade your Play Services and Firebase dependencies to version 15+ (note that they have different versions now)
  • Cancel your google-services upgrade to 3.3.0 until you upgrade to 15+, that is, downgrading the gradle plugin to version 3.2.1.

EDIT 1: There's a known issue about using google-services 3.3 in multimodule apps. That means downgrading to google-services to 3.2.1 may be your only option until a new version that fixes the bug is released.

EDIT 2: The bug mentioned above has been fixed in the version 4.0.1 of the google-services gradle plugin! (and the version 4.0.2 also fixes an NPE that occurred in some cases)

BTW, you should move to FCM. GCM will stop working in a not too distant future.


I got this error when I use google-services:3.3.0.

Downgrade to classpath 'com.google.gms:google-services:3.2.1' in your project .gradle.

It should solve the issue.

Update: It should probably not occur in the current versions.


Faced with similar issue while upgrading to 3.3.1

Fixed it by downgrading to 3.2.1

We can use firebase version >=15 with 3.2.1


Below steps worked for me ---

  1. Go to the android/build.gradle file.
  2. Search for jcentre() method.
  3. Shift all the jcenter() methods to the bottom inside its block.

I faced a similar issue in past few days with.

implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'

solution was to either downgrade to

implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'

or consider leaving Google Cloud Services and upgrading to FCM entirely

Note that they have different version numbers you can look it up here

참고URL : https://stackoverflow.com/questions/50132601/gradle-more-than-one-variant-of-project-mylib-matches-the-consumer-attributes

반응형