gpt4 book ai didi

java - 多个 Dex 文件定义 Landroid/support/v4

转载 作者:行者123 更新时间:2023-12-03 06:13:40 27 4
gpt4 key购买 nike

几个小时以来,我一直在努力解决这个问题。我尝试导入 2bard 的 AndroidPianoView作为一个库项目(PianoView 和 PianoViewExample 都在里面),它们都有一个 support-v4 jar在他们的libs目录。

我的项目在 Android Studio 中。

从一个或两个目录中删除 jar 对我没有好处,我尝试按照 this popular question 中的解决方案进行操作没有成功。

这是运行 gradle -q:app:dependencies 的依赖关系树:

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:22.2.1
| \--- com.android.support:support-v4:22.2.1
| \--- com.android.support:support-annotations:22.2.1
\--- project :PianoViewExample
\--- project :PianoView

以下是 build.gradle 文件:

我的项目
buildscript {
repositories {
mavenCentral() // or jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.ajbowler.jamory"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

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

钢琴查看
buildscript {
repositories {
mavenCentral() // or jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

apply plugin: 'com.android.library'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')

// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

PianoViewExample
buildscript {
repositories {
mavenCentral() // or jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

apply plugin: 'com.android.library'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':PianoView')
}

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')

// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

控制台输出
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/ActivityCompatHoneycomb;
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:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
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 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2

当我 exclude module: 'support-v4' 时会发生什么在主项目中
buildscript {
repositories {
mavenCentral() // or jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.ajbowler.jamory"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile project(':PianoViewExample')
compile('com.android.support:appcompat-v7:23.0.1') {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services'
}
}
}

输出
Error:(8, 8) error: cannot access TaskStackBuilder
class file for android.support.v4.app.TaskStackBuilder not found
Error:(10, 5) error: method does not override or implement a method from a supertype
Error:(12, 9) error: cannot find symbol variable super
Error:(13, 9) error: cannot find symbol method setContentView(int)
Error:(16, 5) error: method does not override or implement a method from a supertype
Error:(19, 9) error: cannot find symbol method getMenuInflater()
Error:(23, 5) error: method does not override or implement a method from a supertype
Error:(35, 16) error: cannot find symbol variable super
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

我真的很感激这方面的一些帮助。我一直无法弄清楚问题来自过去 exclude - 从 PianoView 模块之一中获取支持 jar,但该模块不起作用。

最佳答案

是的,今天刚刚修好了。就我而言,这是 Maven 中支持 v4 和支持 v7 之间的冲突。我所做的只是在主项目的支持 v7 标记中添加支持 v4 的排除标志。
我不得不从 v7 中排除 v4,因为我已经在使用它(v4 的导入位于我的 pom 文件的上方 5 行)。

例子:
http://www.thedevline.com/2014/06/unexpected-top-level-exception.html?m=1

编辑
类似帖子:
Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat .
希望能帮助到你。

Multiple dex files define Landroid/support/v4/ in android studio

关于java - 多个 Dex 文件定义 Landroid/support/v4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600726/

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