尝试构建APK时,Gradle出现意外错误导致构建失败。

4
我写了一小段代码,但每当我尝试构建apk时,就会出现以下错误:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
这里的xxxx是我的用户名,yyyyy是项目名称。 我已经尝试了Stack Overflow上所有可能的解决方案,但我意识到所有这些方案都是关于旧版本的。 我正在使用最新版的Android Studio。我使用最新版本的Android SDK、构建工具、Gradle、JDK 8.0和JRE 7。我还尝试过JRE 8。
build.gradle(module app) :
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "xxxx.yyyyy"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "Unreleased Demo Version"
    testInstrumentationRunner                 
"android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}

请展示您的应用模块的build.gradle文件。 - Abhishek Aryan
如果你还没有找到解决方案,还有一件事情可以尝试。前往你的项目文件夹并删除中间文件夹,然后重新构建你的项目,它就会正常工作。 - Umair
仍然是同样的问题 - Anuraag
libs 文件夹里有哪些 JAR 包? - Abhishek Aryan
没有jar文件。 - Anuraag
6个回答

0

我发现不需要安装JDK和JRE(参考:Android Studio 2.3.2最新下载页面下的系统要求)

并且在programfiles / android-studio中有一个名为“jre”的文件夹。

所以我想卸载JDK和JRE(因为与Java相关的问题)

之后我重新安装了Android Studio。

现在它可以正常运行。 (虽然我没有深入研究,但这对我有所帮助)


哪个操作系统?我遇到了类似的问题。 - tricknology

0

在你的 build.gradle/app 文件中

defaultConfig {
    ....
   //Add this line
    multiDexEnabled true
}

dependencies {
   ....
   //Add this line
   compile 'com.android.support:multidex:1.0.0'
}

1
我已经尝试了所有可能的解决方案,包括这个。它没有帮助到我。 - Anuraag

0
随着Android平台的不断发展,Android应用程序的大小也在不断增长。当您的应用程序及其引用的库达到一定大小时,您会遇到构建错误,表明您的应用程序已经达到了Android应用程序构建架构的限制。 修改模块级build.gradle文件以启用multidex并将multidex库添加为依赖项,如下所示Source
android {
    defaultConfig {


        multiDexEnabled true
    }
}

我已经尝试了所有可能的解决方案,包括这个。它没有帮助到我。 - Anuraag
添加后,转到“文件”->“使缓存无效”/重新启动。 - Sathya Baman
尝试过了,但不起作用。你能通过Teamviewer帮我吗? - Anuraag
好的,请尝试移除'compile 'com.android.support:multidex:1.0.1''。我已经更新了答案。 - Sathya Baman
错误:执行任务“:app:transformClassesWithMultidexlistForDebug”失败。
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: 使用主类为com.android.multidex.ClassReferenceListBuilder的java进程在执行参数为{C:\xxxx\yyyyy\Desktop\VoterSearch\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}时出错。在您的建议之后
- Anuraag
然后检查这个.. https://dev59.com/ZZHea4cB1Zd3GeqPjQL4 - Sathya Baman

0

在 Module:App 的 gradle 文件夹中尝试这个。

 multiDexEnabled true

        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }

0

您还未分享任何代码和相关依赖,所以很难猜测确切的问题。

但从您发布的错误信息来看,我认为您的程序超过了64K个方法的限制。

Apk文件包含以DEX形式的字节码文件,它在单个DEX文件中有65,536个方法的限制。

因此,如果您的应用程序有超过64k个方法,则应该使用多个DEX文件。

启用多个DEX意味着应用构建过程会生成多个DEX文件。

defaultConfig {
....

multiDexEnabled true 
}

dependencies {
....

compile 'com.android.support:multidex:1.0.0'
}

-1

当您超过了65,536个方法引用限制时,就会发生这种情况。

步骤1

您可以将以下内容添加到应用的build.gradle文件中:

    android {
      defaultConfig {
      ...
      minSdkVersion 15 
      targetSdkVersion 25
      multiDexEnabled true
     }
  ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

步骤2A

接下来,您需要按照以下方式扩展Application类

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

或者你可以按照以下步骤进行:

第二步B

public class MyApplication extends MultiDexApplication { ... }

步骤三

最后,按照以下方式更新您的清单文件

<?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>

你能解释一下第二步吗? - Anuraag
你使用的是32位系统还是64位系统? - Farmaan Elahi
Windows 7 32位 - Anuraag
尝试将以下代码设置在您的gradle.properties文件中,并通过转到FILE->Invidate Cahes / restart来使缓存失效。org.gradle.jvmargs=-XX:MaxHeapSize\=2048m -Xmx2048m - Farmaan Elahi
错误:Gradle 执行失败。

原因: 无法启动守护进程。 这个问题可能是由于守护进程的配置不正确引起的。 例如,使用了未被识别的 JVM 选项。 请参考用户指南中关于守护进程的章节,网址为 https://docs.gradle.org/3.5/userguide/gradle_daemon.html 请阅读以下进程输出以获取更多信息:

VM 初始化期间发生错误 无法为 2097152KB 对象堆保留足够的空间
- Anuraag
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接