提问人:shawn_t 提问时间:9/3/2019 更新时间:9/3/2019 访问量:328
任务:transformClassesAndResourcesWithR8ForRelease FAILED 程序类型已存在 *。构建配置
Task :transformClassesAndResourcesWithR8ForRelease FAILED Program type already present *.BuildConfig
问:
我有一个包含多个模块的 Android Studio (3.4.1) cocos2d-x 项目。我的 settings.gradle 文件定义了 3 个模块:
include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
include ':ToaTetrisApp'
project(':ToaTetrisApp').projectDir = new File(settingsDir, 'app')
include ':gameCircleSDK'
注意:gameCircleSDK 不需要设置其 projectDir,因为该目录与 proj.android 中的模块名称匹配
我遇到的问题是,当我构建应用程序的发布版本或尝试 Build->Generate Signed Bundle / APK 时,出现以下错误:
>Task :ToaTetrisApp:transformClassesAndResourcesWithR8ForRelease FAILED
AGPBI: {"kind":"error","text":"Program type already present: com.amazon.ags.BuildConfig","sources":[{}],"tool":"D8"}
注意:com.amazon.ags.BuildConfig 是 gameCircleSDK 模块的自动生成类。GameCircleSDK 的 AndroidManifest.xml 定义了 package=“com.amazon.ags”,这是定义包的唯一位置。
我还搜索了我生成的文件,在发布文件夹中只找到了预期的 BuildConfig.java 文件:com.toa.tetris (ToaTetrisApp)、com.amazon.ags (gameCircleSDK)、org.cocos2dx.lib (cocos2d-x)
我有以下build.gradle文件:
proj.android:build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
proj.android:app:build.gradle [俄罗斯方块应用]
import org.gradle.internal.os.OperatingSystem
apply plugin: 'com.android.application'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
defaultConfig {
applicationId "com.toa.tetris"
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 21
versionName "4.5.1"
multiDexEnabled true
externalNativeBuild {
if (PROP_BUILD_TYPE == 'ndk-build') {
ndkBuild {
targets 'MyGame'
arguments 'NDK_TOOLCHAIN_VERSION=clang'
//arguments 'V=1'
arguments '-j' + Runtime.runtime.availableProcessors()
def module_paths = [project.file("../../cocos2d").absolutePath,
project.file("../../cocos2d/cocos").absolutePath,
project.file("../../cocos2d/external").absolutePath]
if (OperatingSystem.current().isWindows()) {
module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
}
else {
arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
}
}
}
else if (PROP_BUILD_TYPE == 'cmake') {
cmake {
targets 'MyGame'
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
cppFlags "-frtti -fexceptions -fsigned-char"
}
}
}
ndk {
abiFilters = []
abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
}
}
sourceSets.main {
java.srcDir "src"
res.srcDir "res"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "../../Resources"
}
externalNativeBuild {
if (PROP_BUILD_TYPE == 'ndk-build') {
ndkBuild {
path "jni/Android.mk"
}
}
else if (PROP_BUILD_TYPE == 'cmake') {
cmake {
path "../../CMakeLists.txt"
}
}
}
signingConfigs {
release {
<CONTENT REMOVED>
}
debug {
<CONTENT REMOVED>
}
}
buildTypes {
release {
debuggable false
jniDebuggable false
renderscriptDebuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
externalNativeBuild {
ndkBuild {
arguments 'NDK_DEBUG=0'
}
}
}
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
externalNativeBuild {
ndkBuild {
arguments 'NDK_DEBUG=1'
}
}
}
}
}
android.applicationVariants.all { variant ->
// delete previous files first
delete "${buildDir}/intermediates/assets/${variant.dirName}"
variant.mergeAssetsProvider.get().doLast {
copy {
from "${buildDir}/../../../Resources"
into "${buildDir}/intermediates/assets/${variant.dirName}"
exclude "**/*.gz"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: '../gameCircleSDK/libs', include:['*.jar'])
implementation project(':libcocos2dx')
implementation project(':gameCircleSDK')
}
proj.android:gameCircleSDK:build.gradle
apply plugin: 'com.android.library'
android {
signingConfigs {
debug {
<CONTENT REMOVED>
}
}
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
//buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
}
sourceSets.main {
manifest.srcFile "src/main/AndroidManifest.xml"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
//implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
}
proj.android:..:cocos2d:cocos:platform:android:libcocos2dx:build.gradle
apply plugin: 'com.android.library'
android {
signingConfigs {
debug {
<CONTENT REMOVED>
}
}
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
defaultConfig {
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
sourceSets.main {
aidl.srcDir "../java/src"
java.srcDir "../java/src"
manifest.srcFile "AndroidManifest.xml"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: '../java/libs', include: ['*.jar'])
}
我一直在寻找并找到许多建议,并尝试了其中的许多建议,但无济于事。以下是我尝试过的一些事情:
- 我尝试了File->Invalidate Caches / Restart: 注意:我最初在调试构建和运行时遇到了同样的问题,这是解决该问题的解决方案。
- 我尝试运行“gradlew ToaTetrisApp:dependencies”,但我没有看到任何对 com.amazon.ags 的引用,也没有任何重复项。我不确定我是否完全理解输出,但似乎对于调试、发布和测试,依赖项似乎符合预期
- 当然,我曾多次尝试清洁和重建,但无济于事
- 我已将“multiDexEnabled true”添加到我的 app:build.gradle 文件中。我不确定这是否真的起到了作用,或者我是否将其添加到正确的文件中。这似乎并没有解决问题
- 我试图添加'afterEvaluate { generateReleaseBuildConfig.enabled = false }',但同样,我不确定要将其添加到哪个build.gradle,所以我无法让它工作
我希望有人可以解释这个错误的确切含义以及我如何自己追踪和解决此问题。这个项目没有使用很多外部依赖项,所以我希望很容易追踪到底发生了什么以及为什么会出现这个错误。如果您想提供一些建议,请让我知道您希望我将代码添加到哪个 gradle 文件,因为通常不会提及。
答: 暂无答案
评论