今天当我更新了我的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')
}
请帮帮我。
答案 0 :(得分: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);
}
答案 1 :(得分:0)
造成这种情况的原因之一是当您到达65K method limit时。 您可以通过删除未使用的代码/库来解决此问题。为此,您需要查看您的依赖项。要列出您的依赖项,您可以执行
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
中将defaultConfig
设置为true,就像这样
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);
}
答案 2 :(得分:0)
在您的应用程序gradle依赖项
中添加此项compile 'com.android.support:multidex:1.0.1'
在defaultConfig
中添加 multiDexEnabled true
将此添加到您的应用程序gradle
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
同步应用
最后在Manifest文件中添加以下应用程序
android:name="android.support.multidex.MultiDexApplication"
答案 3 :(得分:0)
您似乎使用了不同版本的Android支持库(23.0.1和23.1.1)。也许你应该尝试使用相同的版本。
此外,如前所述,列出您的依赖项以检查它们是否使用与支持库相同的版本:
./gradlew app:dependencies --configuration compile
答案 4 :(得分:0)
总是会发生这种情况,因为您只为发布版本启用了multiDex,而不是调试版本。
试试这个:
defaultConfig {
multiDexEnabled true
}