Java.exe 在 Android Studio 中以非零退出值 2 结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34285406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:41:20  来源:igfitidea点击:

Java.exe finished with non-zero exit value 2 in Android Studio

javaandroidandroid-studio

提问by

This error came after when I added compile 'org.apache.httpcomponents:httpmime:4.2.3'. Can't find solution I also tried multiple dex file true in default config section. I also tried creating another app for testing which was running successfully.

当我添加compile 'org.apache.httpcomponents:httpmime:4.2.3'后出现此错误。找不到解决方案我也在默认配置部分尝试了多个 dex 文件 true。我还尝试创建另一个成功运行的测试应用程序。

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2

错误:任务 ':app:transformClassesWithDexForDebug' 的执行失败。com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79 \bin\java.exe'' 以非零退出值 2 结束

This is my build.gradlefile.

这是我的build.gradle文件。

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            applicationId "com.example.qualwebs.assistme"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
              }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.1'
        compile 'com.android.support:design:23.1.1'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
        compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
        compile 'com.getbase:floatingactionbutton:1.10.1'
        compile 'org.apache.httpcomponents:httpmime:4.2.3'
    }

采纳答案by IntelliJ Amiya

The Android plugin for Gradle available in Android SDK Build Tools 21.1 and higher supports multidex as part of your build configuration. Make sure you update the Android SDK Build Tools tools and the Android Support Repository to the latest version using the SDK Manager before attempting to configure your app for multidex.

Android SDK Build Tools 21.1 及更高版本中提供的适用于 Gradle 的 Android 插件支持将 multidex 作为构建配置的一部分。在尝试为 multidex 配置应用程序之前,请确保使用 SDK 管理器将 Android SDK 构建工具工具和 Android 支持存储库更新到最新版本。

Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:

将应用程序开发项目设置为使用 multidex 配置需要您对应用程序开发项目进行一些修改。具体而言,您需要执行以下步骤:

  1. Change your Gradle build configuration to enable multidex
  2. Modify your manifest to reference the MultiDexApplication class
  1. 更改您的 Gradle 构建配置以启用 multidex
  2. 修改您的清单以引用 MultiDexApplication 类

Modify your app Gradle build file configuration to include the support library and enable multidex output .

修改您的应用程序 Gradle 构建文件配置以包含支持库并启用多索引输出。

    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        ...

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

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

In your manifest add the MultiDexApplicationclass from the multidexsupport library to the application element.

在您的清单中MultiDexApplication,将multidex支持库中的类添加到应用程序元素。

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

Edited

已编辑

You can use

您可以使用

compile 'org.apache.httpcomponents:httpmime:4.5.1' 

Read

https://developer.android.com/intl/es/tools/building/multidex.html

https://developer.android.com/intl/es/tools/building/multidex.html

回答by AndiGeeky

You have problem of multidex file so please add below dependency to your app Gradle file.

您遇到了 multidex 文件的问题,因此请将以下依赖项添加到您的应用程序 Gradle 文件中。

compile 'com.android.support:multidex:1.0.1'

Also add this line:

还要添加这一行:

defaultConfig {

    applicationId 'pkg'
    minSdkVersion 
    targetSdkVersion 
    versionCode 
    versionName 

    // Enable MultiDexing:  https://developer.android.com/tools/building/multidex.html
    multiDexEnabled true
}

Also add below in Manifest.xml :

还在 Manifest.xml 中添加以下内容:

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

Edited :

编辑:

Try the following:

请尝试以下操作:

Change setting

修改设置

Ctrl + Alt + S -> Compiler -> Gradle

Ctrl + Alt + S -> 编译器 -> Gradle

InVM Options field write:

InVM 选项字段写入:

-Xmx2048m -XX:MaxPermSize=512m

-Xmx2048m -XX:MaxPermSize=512m

Add in gradle

在gradle中添加

dexOptions { javaMaxHeapSize "2g" }

dexOptions { javaMaxHeapSize "2g" }

Thanks..!!

谢谢..!!

回答by Sharath

This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.

这个问题很可能是由于超过了 Android 强加的 65K 方法 dex 限制。这个问题可以通过清理项目,从 build.gradle 中的依赖项中删除一些未使用的库和方法,或者通过添加 multidex 支持来解决。

So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.

因此,如果您必须保留库和方法,那么您可以通过在 gradle 配置中声明来启用多 dex 支持。

defaultConfig {        
// Enabling multidex support.
multiDexEnabled true
}