任务:transformClassesAndResourcesWithR8ForRelease FAILED程序类型已经存在* .BuildConfig

时间:2019-09-03 06:42:53

标签: android-gradle-plugin android-studio-3.0 android-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中的模块名称匹配

我遇到的问题是,当我构建应用程序的发行版时,或者尝试构建->生成签名包/ 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 [ToaTetrisApp]

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文件,因为通常没有提到。

0 个答案:

没有答案