Gradle:项目的多个变体:myLib匹配使用者属性

the*_*ous 81 android gradle android-studio android-gradle-plugin

我写了一个图书馆myLib用途RemoteMessageFirebase,应用程序本身也使用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
}
Run Code Online (Sandbox Code Playgroud)

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'
Run Code Online (Sandbox Code Playgroud)

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'
}
Run Code Online (Sandbox Code Playgroud)

testApp\myLib> gradle clean assembleDebug和输出错误testApp\app> gradle clean assembleDebug

项目的多个变体:myLib匹配使用者属性:

  • 配置':myLib:debugApiElements'变种android-aidl:
    • 找到artifactType'android-aidl'但不是必需的.
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'.
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的.
    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'.
    • 需要org.gradle.usage'java-api'并找到兼容的值'java-api'.
  • 配置':myLib:debugApiElements'变种android-classes:
    • 找到artifactType'android-classes'但不是必需的.
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'.
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的.
    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'.
    • 需要org.gradle.usage'java-api'并找到兼容的值'java-api'.
  • 配置':myLib:debugApiElements'变种android-manifest:
    • 找到artifactType'android-manifest'但不是必需的.
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'.
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的.
    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'.
    • 需要org.gradle.usage'java-api'并找到兼容的值'java-api'.
  • 配置':myLib:debugApiElements'变种android-renderscript:
    • 找到artifactType'android-renderscript'但不是必需的.
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'.
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的.
    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'.
    • 需要org.gradle.usage'java-api'并找到兼容的值'java-api'.
  • 配置':myLib:debugApiElements'变量jar:
    • 找到artifactType'jar'但不是必需的.
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'.
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的.
    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'.
    • 需要org.gradle.usage'java-api'并找到兼容的值'java-api'.

Lou*_*CAD 86

google-servicesgradle这个插件是由与谷歌播放服务和火力地堡的工作15+,但你使用它的版本12.0.1.

解决方案是:

编辑1:关于google-services 3.3在多模块应用程序中使用存在一个已知问题.这意味着降级到google-servicesto 3.2.1可能是你唯一的选择,直到发布修复bug的新版本.

编辑2:上面提到的错误已在gradle插件的版本4.0.1google-services修复!(该版本4.0.2还修复了在某些情况下发生的NPE)

顺便说一下,你应该转向FCM. GCM将在不久的将来停止工作.


Hen*_*nte 28

当我使用google-services时出现此错误:3.3.0.

降级到classpath 'com.google.gms:google-services:3.2.1'项目.gradle.

它应该解决这个问题.

  • 我在更新到3.3.0之后遇到了这个问题,但是我们*不能降级*因为这是新的play-services/firebase版本> = 15所需要的.请参阅https://android-developers.googleblog.com/2018/05 /announcing-new-sdk-versioning.html (2认同)

小智 7

升级到3.3.1时面临类似问题

通过降级到3.2.1来修复它

我们可以使用firebase版本> = 15和3.2.1