【问题标题】:gradle 3.1.2 dependency on library's product flavorgradle 3.1.2 对库产品风味的依赖
【发布时间】:2019-08-08 22:33:33
【问题描述】:

Gradle 版本 3.1.2

我有一个应用程序和一个模块。该模块具有产品风味。当我使应用程序依赖于模块时,gradle 失败。这是gradle文件,

应用分级:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.myapplication"
        ...
    }
    buildTypes {
         release {
             ...
         }
    }
}

dependencies {
     implementation fileTree(include: ['*.jar'], dir: 'libs')
     ...
     implementation project(':mylibrary') <- this is the dependency added
}

模块分级:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 19
        ...
    }

    buildTypes {
        release {
            ...
        }
    }

    flavorDimensions 'api'
    productFlavors {
        v1_0 {
            dimension 'api'
        }

        v2_0 {
            dimension 'api'
        }
    }
}

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

以下是gradle产生的错误,

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :mylibrary.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :mylibrary.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :mylibrary.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :mylibrary.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :mylibrary.

如何使用产品风格使应用依赖于模块?

实施项目(路径:':mylibrary',配置:'v1_0')在gradle 3+之后不再工作

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    从 Gradle 3.0 开始,您必须使用 missingDimensionStrategy

    这意味着您需要告诉您的 app 模块您的库具有但您的 app 模块没有的维度使用哪种风格。

    defaultConfig {
        applicationId "com.example.myapplication"
        missingDimensionStrategy 'api', 'v1_0'
        ...
    }
    

    当然,您不仅可以在 defaultConfig 中使用 missingDimensionStrategy,还可以在 debug{}release{} buildTypes 或 productFlavors 中使用 missingDimensionStrategy,如果您稍后添加的话。

    【讨论】:

      猜你喜欢
      • 2013-10-01
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      相关资源
      最近更新 更多