[android]错误︰ 完成带有非零退出值 2

发布时间: 2016/9/26 4:52:31
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有一个问题与 Android studio。当我在我的项目中添加 AndroidNetworking,修改 Manifest.xml 时,它给了我这个错误

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/androidnetworking/AndroidNetworking;
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process '命令' C:\Program Files\Java\jdk1.7.0_75\bin\java.exe ' 完成带有非零退出值 2

这是代码的 Android Manifest (添加 tag <uses-sdk/> ):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="damasoft.mmchat">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" tools:overrideLibrary="com.androidnetworking"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <provider
        android:name="com.ianhanniballake.localstorage.LocalStorageProvider"
        android:authorities="com.ianhanniballake.localstorage.documents"
        android:enabled="@bool/use_provider"
        android:exported="true"
        android:grantUriPermissions="true"
        android:permission="android.permission.MANAGE_DOCUMENTS" >
        <intent-filter>
            <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
        </intent-filter>
    </provider>
    <activity
        android:name="com.ipaulpro.afilechooser.FileChooserActivity"
        android:enabled="@bool/use_activity"
        android:exported="true"
        android:label="@string/choose_file" >
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />

            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Page1" android:label="ManuPost"></activity>
    <activity android:name=".FileChooserActivity"></activity>
</application>

这是我的 build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "damasoft.mmchat"
    minSdkVersion 9
    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.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.amitshekhar.android:android-networking:0.0.1'
}

我试图解决这一问题在 build.gradle,但没有成功

解决方法 1:

在像你 gradle 文件中进行 multiDexEnabled 真实

defaultConfig {
    applicationId "com.am.android"
    minSdkVersion 13
    targetSdkVersion 23
    // Enabling multidex support.
    multiDexEnabled true
}

和编译

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

在你的 Mainactivity

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
官方微信
官方QQ群
31647020