0

今天我更新了我的android stdio,然后我看到了以下错误,我无法理解这些错误的原因,但它给出了很多

truble . 
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2

这些也是在以前的错误下,

Error:Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","sources":[{}]}
AGPBI: {"kind":"simple","text":"com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

这是我的 gradle 文件,

// Top-level build file where you can add configuration options common to all sub-projects/modules.

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1' 
}
buildscript {
    repositories {
        jcenter()
         mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
         mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是第二个 build.gradle 文件,

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.androidanimations:library:1.0.3@aar'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile project(':library')
}

请帮我 。

4

5 回答 5

3
 dependencies {
...
// add this since you are using minSdkVersion less than 21
compile 'com.android.support:multidex:1.0.1'
 }

并像这样在 defaultConfig 中将 multiDexEnabled 设置为 true

defaultConfig {
applicationId "com.shubham.MeraIndore"
minSdkVersion 12
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true

}

 You also need to reference the MultiDexApplication class in your manifest    by adding      android:name="android.support.multidex.MultiDexApplication" to application tag.

注意:如果你的应用扩展了 Application 类,你可以重写 attachBaseContext() 方法并调用 MultiDex.install(this) 来启用 multidex,就像这样。

 @Override
 protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);

}

于 2016-07-19T07:52:01.533 回答
0

造成这种情况的原因之一是当您达到65K 方法限制时。您可以通过删除未使用的代码/库来解决此问题。为此,您需要查看您的依赖项。要列出您的依赖项,您可以执行

gradlew -q dependencies app:dependencies --configuration compile

命令在项目的根目录中。

或者如果没有要删除的代码/库,您可以使用 multidex 支持

dependencies {
    ...
    // add this since you are using minSdkVersion less than 21
    compile 'com.android.support:multidex:1.0.1'
}

并像这样设置multiDexEnabled为truedefaultConfig

defaultConfig {
    applicationId "com.shubham.MeraIndore"
    minSdkVersion 12
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

您还需要通过添加到应用程序标记来引用MultiDexApplication清单中的类。android:name="android.support.multidex.MultiDexApplication"

注意:如果相反,您的应用程序扩展了Application该类,您可以覆盖该attachBaseContext()方法并调用MultiDex.install(this)以启用 multidex,如下所示。

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

有关更多详细信息,请参阅此SO答案和.

于 2016-07-19T06:47:35.240 回答
0

将此添加到您的应用程序 gradle 依赖项中

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

将此添加到您的 defaultConfig

  multiDexEnabled true

将此添加到您的应用程序 gradle

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

同步应用

最后在清单文件中添加以下应用程序

   android:name="android.support.multidex.MultiDexApplication"
于 2016-07-19T06:58:03.523 回答
0

您似乎使用了不同版本的 Android 支持库(23.0.1 和 23.1.1)。也许您应该尝试使用相同的版本。

此外,如前所述,列出您的依赖项以检查它们是否使用与您的支持库相同的版本:

./gradlew app:dependencies --configuration compile
于 2016-07-19T09:56:05.897 回答
0

它总是会发生,因为您只为发布版本启用了 multiDex,而不是为调试版本启用了 multiDex。

试试这个:

defaultConfig {
    multiDexEnabled true
}
于 2016-08-23T02:14:10.053 回答