Android buildTypes与productFlavors错误

如何解决Android buildTypes与productFlavors错误

决定使用Gradle 6.5从Android gradle插件3.5.x切换到gradle插件4.10并错误地卡住了。

这是我的build.gradle

defaultConfig {

    applicationId "com.example.myapp
    targetSdkVersion targetSdkVersionVar
    multiDexEnabled true
}

flavorDimensions "version"

productFlavors {
    kitkat {
        sourceSets { "src/android/kitkat" }
        dimension "version"
        minSdkVersion minSdkKitkat
        targetSdkVersion targetSdkKitkat
        versionNameSuffix "-kitkat"
    }
    nougat {
        sourceSets { "src/android/nougat" }
        dimension "version"
        minSdkVersion minSdkNougat
        targetSdkVersion targetSdkVersionVar
        versionNameSuffix "-nougat"
    }
}


buildTypes {

    debug {
        multiDexKeepFile file('multidex-config.txt')
        multiDexKeepProguard file('multidex-config.pro')
        minifyEnabled false
        zipAlignEnabled true
        sourceSets {

            //main.java.srcDirs += 'src/main/kotlin'
            main {
                java.srcDirs = ['src/android/default/java/','src/common/java/']
                jni.srcDirs = [] //disable ndk support
                manifest.srcFile 'src/android/default/AndroidManifest.xml'
                resources.srcDirs = ['src/android/default']
                aidl.srcDirs = ['src/android/default']
                renderscript.srcDirs = ['src/android/default']
                res.srcDirs = ['src/android/default/res']
                assets.srcDirs = ['src/android/default/assets']
            }
            test {
                java.srcDirs = ['src/test/java']
            }
            androidTest {
                java.srcDirs = ['src/androidTest/java']
            }
        }
    }
    release {
        multiDexKeepFile file('multidex-config.txt')
        multiDexKeepProguard file('multidex-config.pro')
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        zipAlignEnabled true
        sourceSets {

            main {
                java.srcDirs = ['src/android/default/java/','src/common/java/']
                jni.srcDirs = [] //disable ndk support
                manifest.srcFile 'src/android/default/AndroidManifest.xml'
                resources.srcDirs = ['src/android/default']
                aidl.srcDirs = ['src/android/default']
                renderscript.srcDirs = ['src/android/default']
                res.srcDirs = ['src/android/default/res']
                assets.srcDirs = ['src/android/default/assets']
            }
            test {
                java.srcDirs = ['src/test/java']
            }
            androidTest {
                java.srcDirs = ['src/androidTest/java']
            }
        }
    }
}

尝试构建时,我收到以下错误消息:

Could not determine the dependencies of task ':app:checkKitkatReleaseLibraries'.
> Could not resolve all task dependencies for configuration ':app:kitkatReleaseReverseMetadataValues'.
   > Could not resolve project :app.
     Required by:
         project :app
      > The consumer was configured to find a usage of 'android-reverse-meta-data' of a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release',attribute 'version' with value 'kitkat'. However we cannot choose between the following variants of project :app:
          - kitkatDebugAndroidTestCompile
          - kitkatDebugAndroidTestRuntime
          - kitkatDebugRuntime
          - kitkatDebugUnitTestCompile
          - kitkatDebugUnitTestRuntime
          - kitkatReleaseRuntime
          - kitkatReleaseUnitTestCompile
          - kitkatReleaseUnitTestRuntime
          - nougatDebugAndroidTestCompile
          - nougatDebugAndroidTestRuntime
          - nougatDebugRuntime
          - nougatDebugUnitTestCompile
          - nougatDebugUnitTestRuntime
          - nougatReleaseRuntime
          - nougatReleaseUnitTestCompile
          - nougatReleaseUnitTestRuntime
        All of them match the consumer attributes:
          - Variant 'kitkatDebugAndroidTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatDebugAndroidTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatDebugRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatDebugUnitTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatDebugUnitTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatReleaseRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatReleaseUnitTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'kitkatReleaseUnitTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatDebugAndroidTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatDebugAndroidTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatDebugRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatDebugUnitTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatDebugUnitTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatReleaseRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatReleaseUnitTestCompile' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
          - Variant 'nougatReleaseUnitTestRuntime' capability myapp:app:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
                  - Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Doesn't say anything about version (required 'kitkat')
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'kitkatDebugApiElements' capability myapp:app:unspecified declares a component,as well as attribute 'version' with value 'kitkat':
              - Incompatible because this component declares an API of a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a usage of 'android-reverse-meta-data' of a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release'
          - Variant 'kitkatDebugRuntimeElements' capability myapp:app:unspecified declares a component,as well as attribute 'version' with value 'kitkat':
              - Incompatible because this component declares a runtime of a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release'
          - Variant 'kitkatReleaseApiElements' capability myapp:app:unspecified declares a component,attribute 'version' with value 'kitkat':
              - Incompatible because this component declares an API of a component and the consumer needed a usage of 'android-reverse-meta-data' of a component
          - Variant 'kitkatReleaseRuntimeElements' capability myapp:app:unspecified declares a component,attribute 'version' with value 'kitkat':
              - Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'android-reverse-meta-data' of a component
          - Variant 'nougatDebugApiElements' capability myapp:app:unspecified:
              - Incompatible because this component declares an API of a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug',attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component,attribute 'version' with value 'kitkat'
          - Variant 'nougatDebugRuntimeElements' capability myapp:app:unspecified:
              - Incompatible because this component declares a runtime of a component,attribute 'version' with value 'kitkat'
          - Variant 'nougatReleaseApiElements' capability myapp:app:unspecified declares a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
              - Incompatible because this component declares an API of a component,as well as attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component,as well as attribute 'version' with value 'kitkat'
          - Variant 'nougatReleaseRuntimeElements' capability myapp:app:unspecified declares a component,as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
              - Incompatible because this component declares a runtime of a component,as well as attribute 'version' with value 'kitkat'

在此之前,当我使用gradle-tools v 3.x-运行正常时。

有什么想法,想法,提示和线索吗?

解决方法

好吧,为了使用不同的后端,我不会指定比调试和发布更多的构建类型。相反,我将使用其中一些技巧:

  • 更多口味
  • 自定义构建配置字段(文档here),
  • 组合多种产品口味(文档here)。

您可以使用BuildConfig类在应用程序代码中访问构建类型,构建风格和自定义字段。

具有简单口味的方法

  • 构建类型:
    • debug
    • release
  • 香料:
    • dev
    • test
    • live

哪些会导致这些生成变体(您不必全部使用它们):

  • devDebug
  • devRelease
  • testDebug
  • testRelease
  • liveDebug
  • liveRelease

使用尺寸组合多种口味的方法

  • 香料尺寸:

    • backend
    • target
  • 构建类型:

    • debug
    • release
  • 香料:

  • target维度:

    • dev
    • test
    • live
  • backend维度:

    • production
    • test

哪些会导致这些生成变体(再次,您不必全部使用它们):

  • productionDevDebug
  • productionDevRelease
  • productionTestDebug
  • productionTestRelease
  • productionLiveDebug
  • productionLiveRelease
  • testDevDebug
  • testDevRelease
  • testTestDebug
  • testTestRelease
  • testLiveDebug
  • testLiveRelease

使用构建字段

在构建类型和构建风味声明中使用附加值,例如:

buildConfigField "boolean","production_backend","false"

buildConfigField "String","backend","\"production\""

关注此链接https://www.journaldev.com/21533/android-build-types-product-flavors

,

您遇到的问题似乎是您的主项目使用了具有风味维度的库,而您的应用程序不知道要使用哪一个。您应该在 defaultConfig 块中使用 missingDimensionStrategy 来指定默认风格。例如:

missingDimensionStrategy 'dimension','flavor1','flavor2'

请查看 this 链接了解更多详情。

,

在@Chriki的评论之后,他试图提出可重复性最小的问题,并突然找到了解决方案。魔术在声明中:

android {
    ...
    dynamicFeatures = [":app"]
}

每当我对此行发表评论时,一切正常。

P.S。这应该是辐射辐射,用于记录日志/调试消息,而实际上没有这些日志/消息。最终,我花了将近一个星期的时间来寻找解决方案,最后却偶然发现了。

如果@Chriki发布答案,我将奖励他。

,

我遇到了同样的问题,但我正在处理多 gradle 文件项目,在每个项目上添加了变体后,它工作正常。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-