Android Studio 3.0 编译问题(无法选择配置)

2024-03-04

最新 3.0 版本(Beta 2)的问题 我的项目有 1 个由第三方提供的子模块,因此我只能访问他们的 build.gradle。

我的项目有 3 种风格:snap、uat、生产。每个都有 2 种构建类型:调试和发布。当我尝试构建时我得到了这个。

Error:Cannot choose between the following configurations of project :lp_messaging_sdk:
  - debugApiElements
  - debugRuntimeElements
  - releaseApiElements
  - releaseRuntimeElements
All of them match the consumer attributes:
  - Configuration 'debugApiElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  - Configuration 'debugRuntimeElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.
  - Configuration 'releaseApiElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
  - Configuration 'releaseRuntimeElements':
      - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
      - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
      - Found org.gradle.api.attributes.Usage 'java-runtime' but wasn't required.

我读到子模块和构建类型存在问题,但后来读到它已修复。 您必须将相同的构建类型或其他内容添加到子模块 build.gradle 中,然后添加

buildTypeMatching  'debug', 'release'

但是,当我这样做时,我收到此错误,

Error:Could not select value from candidates [debug, release] using AlternateDisambiguationRule.BuildTypeRule.

apply plugin: 'com.android.application'

android {

    repositories {
        flatDir {
            dirs project(':lp_messaging_sdk').file('aars')
        }
    }

    // Android parameters
    compileSdkVersion = 26
    buildToolsVersion = '26.0.1'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        preDexLibraries true
    }

    defaultConfig {
        minSdkVersion 19
        versionName buildName
        versionCode buildVersion
        multiDexEnabled true
        resConfigs "en", "fr", "fr-rCA"
    }

    signingConfigs {
        release {

        }
    }

    flavorDimensions "default"

    productFlavors {
        snap {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionReleaseNotesFilePath = 'changelog.txt'
            ext.betaDistributionNotifications = true
            dimension "default"
        }

        uat {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionNotifications = true
        }

        production {
        }
    }

    buildTypes {
        debug {
            versionNameSuffix createVersionNameSuffix()
            applicationIdSuffix '.debug'
            minifyEnabled true
            testCoverageEnabled false
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
            ext.enableCrashlytics = false
        }

        release {
            versionNameSuffix createVersionNameSuffix()
            minifyEnabled true
            testCoverageEnabled = false
            signingConfig signingConfigs.release
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
        }

    }

    //Used to ignore duplicated entries added to meta-inf
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    dexOptions {
        javaMaxHeapSize "2048m"
        dexInProcess true
    }

    lintOptions {
        abortOnError true
        xmlReport true
        htmlReport true
        disable 'MissingTranslation', 'InvalidPackage'
        disable 'GradleCompatible', 'GradleCompatible'
        disable 'NewApi', 'NewApi'
        disable 'GradleDependency'
        disable 'UnusedResources'
        disable 'IconDensities'
        disable 'TypographyDashes'
        disable 'ContentDescription'
        htmlOutput file("$project.buildDir/reports/lint/lint-result.html")
        xmlOutput file("$project.buildDir/reports/lint/lint-result.xml")
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

greendao {
    schemaVersion 13
    targetGenDir 'src/main/java/'
}

ext.betaDistributionReleaseNotes = System.getenv("CHANGELOG")

def createVersionNameSuffix() {
    def buildNumber = System.env.BUILD_NUMBER
    def buildTimestamp = new Date().format('HH:mm dd/MM/yy')
    return buildNumber ? " ($buildNumber)" : " ($buildTimestamp)"
}

def getBuildVersionFromName(String buildName) {
    List data = buildName.tokenize(".")
    String resultString = "19";

    for (String s : data) {
        resultString += s;
    }

    if (System.env.BUILD_NUMBER) {
        resultString += System.env.BUILD_NUMBER
    }

    return Integer.parseInt(resultString);
}

//Verify the app before creating a Pull Request
task verifyPR
verifyPR.dependsOn('clean')
verifyPR.dependsOn('lint')
verifyPR.dependsOn('checkstyle')
verifyPR.dependsOn('pmd')
verifyPR.dependsOn('testSnapDebugUnitTest')

dependencies {
    // Android Dependencies
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:design:26.0.1'
    compile 'com.android.support:recyclerview-v7:26.0.1'
    compile 'com.android.support:multidex:1.0.2'

    // Dagger Dependencies
    apt 'com.google.dagger:dagger-compiler:2.11'
    compile 'org.glassfish:javax.annotation:10.0-b28'
    compile 'com.google.dagger:dagger:2.11'

    // Rx Dependencies
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.3.0'
    compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.4.0'
    compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
    compile 'com.squareup.whorlwind:whorlwind:1.0.1'
    compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar'
    compile 'com.jenzz:RxAppState:2.0.0'

    // Tools
    compile 'com.crashlytics.sdk.android:crashlytics:2.6.5'

    // ButterKnife
    compile 'com.jakewharton:butterknife:8.4.0'

    // Google Maps
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile "com.google.android.gms:play-services-analytics:11.0.4"
    compile 'com.google.android.gms:play-services-location:11.0.4'
    compile 'com.google.android.gms:play-services-places:11.0.4'
    compile 'com.google.android.gms:play-services-gcm:11.0.4'

    // Geofence
    compile('pl.charmas.android:android-reactive-location:0.10@aar') {
        transitive = true
    }

    // Retrofit
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'

    // OKHTTP
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'

    // Libphonenumber
    compile 'com.googlecode.libphonenumber:libphonenumber:7.3.2'

    // UI
    compile 'com.tubb.smrv:swipemenu-recyclerview:5.0.2'

    // EventBus
    compile 'org.greenrobot:eventbus:3.0.0'

    // Database
    compile 'org.greenrobot:greendao:3.2.0'

    // Chuck HTTP Inspector
    debugCompile 'com.readystatesoftware.chuck:library:1.0.4'
    releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.0.4'

    // ViewPager Indicator
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'

    // Amplitude
    compile 'com.amplitude:android-sdk:2.13.2'

    // TESTS
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.10.19"
    testCompile "org.powermock:powermock-module-junit4:1.6.5"
    testCompile "org.powermock:powermock-module-junit4-rule:1.6.4"
    testCompile "org.powermock:powermock-api-mockito:1.6.5"
    testCompile "org.powermock:powermock-classloading-xstream:1.6.4"

    compile project(':lp_messaging_sdk')
}

这是第 3 方库 build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 250
        versionName "2.5.0"
    }

    flavorDimensions "default"

    productFlavors {
        snap {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionReleaseNotesFilePath = 'changelog.txt'
            ext.betaDistributionNotifications = true
            dimension "default"
        }

        uat {
            ext.betaDistributionGroupAliases = "INTERNAL"
            ext.betaDistributionNotifications = true
        }

        production {

        }
    }

    signingConfigs {
        release {

        }
    }

    buildTypeMatching 'snap', 'debug', 'release'

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            minifyEnabled true
            testCoverageEnabled false
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
            ext.enableCrashlytics = false
        }

        release {
            minifyEnabled true
            testCoverageEnabled = false
            signingConfig signingConfigs.release
            buildConfigField "String", "PLAY_STORE_VERSION_NAME", '"' + PLAY_STORE_VERSION_NAME + '"'
            // Workaround for : https://code.google.com/p/android/issues/detail?id=212882
            proguardFiles fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()
        }
    }

    defaultConfig {
        consumerProguardFiles 'proguard.cfg'
    }

    repositories {
        flatDir {
            dirs 'aars'
        }
    }

    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:design:26.0.1'
    compile 'com.android.support:recyclerview-v7:26.0.1'
    compile 'com.android.support:percent:26.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.neovisionaries:nv-websocket-client:1.31'
    compile 'com.squareup.okhttp3:okhttp:3.8.0'

    compile(name: 'infra', ext: 'aar')
    compile(name: 'messaging', ext: 'aar')
    compile(name: 'messaging_ui', ext: 'aar')
    compile(name: 'ui', ext: 'aar')
}

有人知道我该如何解决这个问题吗? 谢谢


Try

implementation project(path: ':lp_messaging_sdk', configuration: 'default')

Note:

您可以通过将 gradle 更新为来避免此错误4.3 检查这个 https://github.com/gradle/gradle/issues/3009.

解释 :

Using 依赖配置 https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html#configurations可以轻松定义和指定在子项目中使用的内容。

在我的回答中,我们使用了default配置,这将仅向其他 Android 项目和模块发布和公开“发布”风格。

假设您只需要在演示风味或发布风味中包含此风味,就像 https://docs.gradle.org/current/userguide/dependency_management.html#sub:configurations :

configurations {
  // Initializes placeholder configurations that the Android plugin can use when targeting
  // the corresponding variant of the app.
  demoDebugCompile {}
  fullReleaseCompile {}
  ...
}
dependencies {
  // If the library configures multiple build variants using product flavors,
  // you must target one of the library's variants using its full configuration name.
  demoDebugCompile project(path: ':lp_messaging_sdk', configuration: 'demoDebug')
  fullReleaseCompile project(path: ':lp_messaging_sdk', configuration: 'fullRelease')
  ...
}

因此,在您的情况下,您可以使用您的构建风格,这就是错误日志中出现的内容。

Cannot choose between the following configurations of project :lp_messaging_sdk

这意味着你的lp_messaging_sdk有各种构建配置:-

  - debugApiElements
  - debugRuntimeElements
  - releaseApiElements
  - releaseRuntimeElements

android-studio 告诉你,“我无法从这些不同的配置中选择一种,你能为我定义一个吗?”

您可以阅读更多内容here https://developer.android.com/studio/projects/android-library.html#publish_multiple_variants.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Studio 3.0 编译问题(无法选择配置) 的相关文章

随机推荐

  • Cypress.io 中选择器的存储位置

    我是赛普拉斯的新手 避免将选择器 定位器硬编码到每个规范中的最佳方法是什么 在其他框架中 我们将创建一个包含所有选择器的配置文件 并让规范引用它 场景 我可能有一个在多个规范中使用的选择器 如果选择器发生变化 我不想在每个规范中更改它 我宁
  • 添加到多个 std 容器时 C++ 中的异常安全

    我有一些代码添加到std vector and a std map创建对象后 v push back object std vector m object gt id object std map 我想让这个有一个强有力的例外保证 通常 为
  • 与php中的另一个数组合并后如何从数组中删除重复元素?

    我正在尝试编写程序来计算指定开始日期后的接下来 20 个日期 然后从 20 个日期中排除周末 Holidays Array holidays 2016 12 13 2016 12 24 以及结果数组 其中仅包含除周六和周日之外的工作日 在假
  • Keycloak,如果选择更新密码操作,则不返回访问令牌

    我正在打电话 auth realms master protocol openid connect token通过在正文中发送以下内容来获取访问令牌 grant type password client id example docker
  • 如何使用 JavaScript 在 Hackerrank 中发出 AJAX 请求?

    我打开 Hackerrank 示例测试并尝试使用可能用于进行 AJAX 调用的方法 XMLHttpReq fetch等等 它们都不起作用 XHR and fetch方法不可用 First fetch async function myFet
  • 维纳滤波

    我想编写一个维纳滤波器来改善图像 我不想使用傅立叶 我知道有一个基于中值和方差的算法 但我找不到它 你们能帮我吗 http en wikipedia org wiki Wiener filter http en wikipedia org
  • 如何为新样式表生成 CSS 变量值

    我正在开发一个项目 用户可以从颜色输入中选择颜色 并使用 CSS 变量动态创建自己的主题 我希望用户能够下载包含他们选择的值的整个 CSS 文件 My issue 下载的CSS文件不显示实际的颜色值 而是显示变量名称 NOT WANTED
  • Python:CGI在脚本退出前更新网页

    好吧 这是我的情况 我编写了一个带有文本区域的 HTML 表单 该文本区域向我的 python 脚本提交 POST 请求 我使用 cgi 库来解析文本区域并将其拆分为一个数组 然后 我使用循环处理这些项目并在处理时打印它们 看来 即使我将打
  • JavaScript 和 Java 有什么区别?

    Locked 这个问题及其答案是locked help locked posts因为这个问题是题外话 但却具有历史意义 目前不接受新的答案或互动 JavaScript 和 Java 有什么区别 Java 和 Javascript 很相似 就
  • 使用operator[]时如何区分读/写操作

    我需要编写一个带有重载运算符 的类 当使用运算符 读取或写入数据时 该类具有不同的行为 为了给出我想要实现的目标的实际示例 假设我必须编写一个名为 PhoneBook 的类的实现 该类可以按以下方式使用 PhoneBook phoneBoo
  • Angular 2 路由器导航功能不起作用

    我的路由器功能 导航 有问题 在我的 AppComponent 中 RouteConfig path home name Home component HomeComponent useAsDefault true data user nu
  • 如何在 Visual Studio 2010 Express for Windows Phone 上安装便携式库工具

    我一直在尝试安装可移植库工具并使用 Visual Studio 2010 Express for Windows Phone 创建可移植类库 看起来它应该可以工作 因为 PCL 说它支持 Visual Studio Express 不幸的是
  • 期望脚本在单独调用时有效,但不能作为盐状态

    我正在尝试通过expect 进行scp 和ssh 操作 如果我直接从终端调用下面的脚本 则它可以工作 usr bin expect myexpect sh但是当我使用 salt 运行它时 第一个 scp 命令在第二个 ssh 失败的地方起作
  • Golang - 解析嵌套 JSON

    我正在使用上班族 https github com benmanns goworker处理请求作业 一个作业有一个有效负载 它有一个嵌套的 JSON 结构 如下所示 key a val a key b val b files key a a
  • PHP Web 应用程序构建系统 [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我想开始自动化更多的网络开发过程 所以我正在寻找一个构建系统 我主要在 Mac OS X 上编写 PHP 应用程序 并通过 FTP 部署 Lin
  • Bundler 通过 RVM 提供什么?

    我不确定这两个工具之间有什么区别 似乎有很大的重叠 但我一直在使用 RVM 并面临一些不兼容的问题 Bundler 做了哪些 RVM 没有做的事情 它们有不同的目的 RVM 创建一个沙箱来管理您的 Ruby 安装 作为其中的一部分 它还允许
  • 如何在源不存在的情况下显示默认图像

    我在 myasp net MVC Web 应用程序中有以下代码 a href Content uploads item ID png img class thumbnailimag src Content uploads item ID p
  • AS3 字符串内存泄漏

    我已经在 AS3 中编程了一段时间 发现一个非常奇怪的问题 字符串没有明显的原因挂在内存上 下面的程序只是用随机字符串更改 label text 属性 它工作正常 但是当我查看 Flex 探查器 我注意到字符串的数量正在稳步增加 我尝试执行
  • 如何将 CCSprite 从一个父级转移到另一个父级?

    我有一个CCSprite called sprite那是一个孩子CCLayer called movingLayer它本身就是当前的子项CCLayer运行我的游戏逻辑 所以它是self在这种情况下 movingLayer以永远重复的动作在屏
  • Android Studio 3.0 编译问题(无法选择配置)

    最新 3 0 版本 Beta 2 的问题 我的项目有 1 个由第三方提供的子模块 因此我只能访问他们的 build gradle 我的项目有 3 种风格 snap uat 生产 每个都有 2 种构建类型 调试和发布 当我尝试构建时我得到了这