为Gradle 3.0.0+构建多味道失败

时间:2018-02-02 02:14:56

标签: android gradle build.gradle android-productflavors

我有三个模块,一个app和两个库模块,commonsdk。依赖关系是app - > common - > sdk

app

的build.gradle的Flavor配置
flavorDimensions "default"

productFlavors {
    merchant {
        dimension "default"
    }
    consumer {
        dimension "default"
    }
}

common

的build.gradle的Flavor配置
flavorDimensions "default"

productFlavors {
    merchant {
        dimension "default"
    }
    consumer {
        dimension "default"
        missingDimensionStrategy 'default', 'consumerABC' // for library dependency includes a flavor dimension that your app does not.
        matchingFallbacks = ['consumerABC'] // for app includes flavors that the library does not.
    }
}

sdk的build.gradle的Flavor配置,这里是与其他模块的味道差异,因为某种原因,味道名称之一不匹配。

flavorDimensions "default"

productFlavors {
    merchant {
        dimension "default"
    }
    consumerABC {
        dimension "default"
    }
}

但是在构建项目时得到了异常:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:processConsumerDebugResources'.
> Could not resolve all task dependencies for configuration ':app:consumerDebugRuntimeClasspath'.
   > Could not resolve project :sdk.
     Required by:
         project :app > project :common
      > Unable to find a matching configuration of project :sdk:
          - Configuration 'consumerABCDebugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'consumerABCDebug' but wasn't required.
              - Required default 'consumer' and found incompatible value 'consumerABC'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'consumerABCDebugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'consumerABCDebug' but wasn't required.
              - Required default 'consumer' and found incompatible value 'consumerABC'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.
          - Configuration 'consumerABCReleaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'consumerABCRelease' but wasn't required.
              - Required default 'consumer' and found incompatible value 'consumerABC'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'consumerABCReleaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'consumerABCRelease' but wasn't required.
              - Required default 'consumer' and found incompatible value 'consumerABC'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.
          - Configuration 'merchantDebugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'merchantDebug' but wasn't required.
              - Required default 'consumer' and found incompatible value 'merchant'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'merchantDebugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'merchantDebug' but wasn't required.
              - Required default 'consumer' and found incompatible value 'merchant'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.
          - Configuration 'merchantReleaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'merchantRelease' but wasn't required.
              - Required default 'consumer' and found incompatible value 'merchant'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found incompatible value 'java-api'.
          - Configuration 'merchantReleaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'merchantRelease' but wasn't required.
              - Required default 'consumer' and found incompatible value 'merchant'.
              - Required org.gradle.api.attributes.Usage 'java-runtime' and found compatible value 'java-runtime'.

基本上我只是遵循Use variant-aware dependency management的文件。这个问题一直很烦人,希望有人可以帮助我。感谢。

0 个答案:

没有答案