LibGDX Android 部署中的 transformClassesWithDexForDebug 执行失败

Failed execution of transformClassesWithDexForDebug in LibGDX Android deploy

我正在尝试 运行 为我的 LibGDX 项目构建 Android,当构建尝试执行 android:transformClassesWithDexForDebug 时出现错误。我已经为这个问题寻找了一段时间的解决方案,none 的建议似乎奏效了。我正在 运行 设置一台 Linux 内存为 16GB 的机器,因此 RAM 问题的介词不太可能。我为我的应用程序启用了 Dex,将 Dex 添加为依赖项,降低了目标 SDK 版本,清理并重建了项目,重新启动了 Android Studio,重新启动了我的计算机,尝试了 [=25= 的最新稳定版本] Studio 和 Beta Canary 9 发布,都无济于事。我收到的关于执行失败的消息是:

Error:Execution failed for task ':android:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/programs/android-studio-preview/jre/bin/java'' finished with non-zero exit value 1

这是我当前 android 模块的 build.gradle 文件:

android {
    buildToolsVersion '21.1.2'
    compileSdkVersion 21
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
    packagingOptions {
        exclude 'META-INF/robovm/ios/robovm.xml'
    }
    defaultConfig {
        applicationId "com.bradvok.gravityballz"
        minSdkVersion 21
        targetSdkVersion 21
        multiDexEnabled true
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/arm64-v8a/").mkdirs();
    file("libs/x86_64/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
        if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if (jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if (outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}
task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.bradvok.gravityballz/com.bradvok.gravityballz.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    classpath {
        plusConfigurations += [project.configurations.compile]
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}
// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [COMPILE: [plus: [project.configurations.compile]]]

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value: "true")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

当前清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxxxxxx.xxxxxxxxxxxx"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="25" android:targetSdkVersion="25" />

    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >
        <activity
            android:name="com.xxxxxxx.xxxxxxxxxxxx.AndroidLauncher"
            android:label="@string/app_name" 
            android:screenOrientation="landscape"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我尝试了 21-25 的编译 SDK 版本、目标 SDK 版本和最低 SDK 版本的几乎所有组合。我正在测试的 phone 是 HTC One 运行ning API 级别 21,并且没有可用的更新。话虽如此,问题可能出在我的 phone 上吗?还值得一提的是,不久前我能够 运行 在应用程序的早期版本上成功构建,当我恢复到该版本时,出现了同样的问题。同样,我已经参考了与此问题相关的所有其他 Whosebug 线程,但到目前为止 none 的解决方案已经能够解决我遇到的问题。还有什么我可以尝试的吗?

根据Android doc :

android {
   compileSdkVersion 26
   buildToolsVersion "21.1.2"

   defaultConfig {
      ...
      minSdkVersion 15
      targetSdkVersion 21
      ...

      // Enabling multidex support.
      multiDexEnabled true
   }
   ...
}

dependencies {
   compile 'com.android.support:multidex:1.0.1'    <-- Not required when minimum sdk is >=21
}

除了在 build.gradle 中进行修改外,您还需要编辑清单文件以在 <application> 标记中设置 android:name,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myapp">
      <application
        android:name="android.support.multidex.MultiDexApplication" >
        ...
     </application>
</manifest>