gpt4 book ai didi

android - 无法在 productFlavors 中添加 buildConfigField

转载 作者:可可西里 更新时间:2023-11-01 19:10:13 33 4
gpt4 key购买 nike

在我的 android{} 部分,我尝试为可能免费和付费的应用程序放置两种不同的构建类型。

遗憾的是我遇到了 gradle 错误:

Gradle 'android-Transport' project refresh failed: Build script error, unsupported Gradle DSL method found: 'buildConfigField()'! Possible causes could be: - you are using Gradle version where the method is absent - you didn't apply Gradle plugin which provides the method - or there is a mistake in a build script

这是我在 gradle 构建中的 android{} 部分:

android {
compileSdkVersion 19
buildToolsVersion "19.0.3"

defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}

buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}

debug {
debuggable true
runProguard false
}
}

productFlavors {
free {
packageName "pl.grzeslowski.transport.free"
buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.FREE"
}

paid {
packageName "pl.grzeslowski.transport.paid"
buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.PAID"
}
}
}

这是我的控制台日志:

Executing tasks: [:transport:compileDebugJava]

Configuration on demand is an incubating feature. Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/sdklib/22.5.3/sdklib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/22.5.3/ddmlib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.8.3/builder-model-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/22.5.3/manifest-merger-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/sdk-common/22.5.3/sdk-common-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.8.3/builder-test-api-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/common/22.5.3/common-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-api/22.5.3/lint-api-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/dvlib/22.5.3/dvlib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/22.5.3/layoutlib-api-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.jar Download http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.jar Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.jar Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.jar

FAILURE: Build failed with an exception.

  • Where: Build file 'D:\Programowanie\GitProjects\transport\android-Transport\transport\build.gradle' line: 77

  • What went wrong: A problem occurred evaluating project ':transport'.

    Could not find method buildConfigField() for arguments [transport.product_flavors.MonetizationType] on GroupableProductFlavorDsl_Decorated{name=free, minSdkVersion=-1, targetSdkVersion=-1, renderscriptTargetApi=-1, renderscriptSupportMode=null, renderscriptNdkMode=null, versionCode=-1, versionName=null, packageName=transport.free, testPackageName=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null}.

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

构建失败

总时间:9.781 秒

最佳答案

buildConfigField 行的正确语法是:

buildConfigField "boolean", "MY_FLAG", "true"

换句话说,字符串需要用逗号分隔。

关于android - 无法在 productFlavors 中添加 buildConfigField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23267365/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com