gpt4 book ai didi

android - 顶级异常 - Android Studio

转载 作者:行者123 更新时间:2023-11-29 20:55:56 25 4
gpt4 key购买 nike

我在 android studio 中遇到顶级异常,我正在使用 appcompat 和滑动菜单库。我知道我遇到异常是因为 Android 支持库的冲突,如 stackoverflow 中的一些先前线程中所述。我已经尝试了线程中显示的所有方法,例如包括配置等。

这是我的 Build.gradle(root)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}

allprojects {
repositories {
jcenter()
}
}

这是我的 Build.Gradle(App)

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion '21.1.1'

defaultConfig {
applicationId "com.danaraddi.cprograms"
minSdkVersion 8
targetSdkVersion 21
versionCode 9
versionName "7.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
}

// animations
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0@aar'
compile 'com.daimajia.androidanimations:library:1.0.8@aar'
}

// inject views
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.jakewharton:butterknife:5.1.2'
}

dependencies {
// Your other dependencies go here
compile project(':library')
}

这是我的 Build.Gradle(Lib - SlidingMenu)

    buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'android-library'

dependencies {
compile 'com.android.support:support-v4:13.0.0'
}

android {
compileSdkVersion 21
buildToolsVersion '21.1.1'

defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}

sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']

manifest.srcFile 'AndroidManifest.xml'
}
}

}

这是我的日志猫

Error:Execution failed for task ':app:dexDebug'.

Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)

PS : 我在 root 和 app build.gradle 中也有配置,它在一个干净的项目之后构建成功,然后在同样的错误之后构建。

最佳答案

添加

dexOptions {
preDexLibraries = false
}

代替

dexOptions {
incremental true
}

到android block 内的build.gradle文件

关于android - 顶级异常 - Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com