我是Android工作室的一个初学者,我试图用mysql和一个android数据库执行数据库同步。在遵循指南之后(它没有提到gradle的东西,所以我必须即兴发挥)我留下了波纹管错误 在搜索之后我被告知它可能是我的依赖,但到目前为止我还没看多少
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/gson-2.2.2.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/android-async-http-1.4.4.jar')
}
.idea文件夹中的库看起来像这样
libraries
android_async_http_1_4_4.xml
android_support_v4.xml
appcompat_v7_21_0_3.xml
gson_2_2_2.xml
support_annotations_21_0_3.xml
support_v4_21_0_3.xml
这是我得到的错误
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Developer Tools/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /Volumes/Untitled/You copy/app/build/intermediates/dex/debug --input-list=/Volumes/Untitled/You copy/app/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
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)
感谢您提供给我的任何帮助
答案 0 :(得分:1)
Gradle知道如何解决依赖冲突。你可以在这里阅读:https://gradle.org/docs/current/userguide/dependency_management.html。
所以错误不是因为appcompat
与support-v4
冲突。
看起来你引用了libs
文件夹中的两次库。
使用:
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/gson-2.2.2.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/android-async-http-1.4.4.jar') }
或:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
但是,我建议您在引用support-v4
gson
,android-async
和appcompat-v7.
答案 1 :(得分:0)
Gradle
依赖关系,AppCompatv7
也会带来Supportv4
。因此,只需删除Supportv4
.jar
,因为您不小心添加了两次。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/gson-2.2.2.jar')
compile files('libs/android-support-v4.jar') // <-- remove jar
compile files('libs/android-async-http-1.4.4.jar')
}
我还将您的.jars
升级为Gradle
个依赖关系。
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0' // <-- upgraded
compile 'com.google.code.gson:gson:2.3.1' // <-- upgraded to gradle dependency
compile 'com.loopj.android:android-async-http:1.4.4' // <-- upgraded to gradle dependency
}