我可以与许多库集成(添加和工作).
但至于ActionBarSherlock库,我遇到了很多问题.
第一个问题是多个dex文件定义的流行问题,
我知道重复的android-support-v4.jar会导致它,但我现在无法解决这个问题:
Error:Execution Failed for task ':fitness:dexDebug'. Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103)
我在same error中听到了答案.它使用了:
dependencies { compile('...') { exclude module: 'support-v4' } compile 'com.android.support:support-v4:18.0.+' }
但是我收到了第二个问题:发现了不支持的Gradle DSL方法:’exclude()’!错误.
因此我改变了主模块的build.gradle,如下所示:
//configurations { // all*.exclude group: 'com.android.support',module: 'support-v4' //} dependencies { compile fileTree(dir: 'libs',include: '*.jar') compile project(':google-play-services') compile files('/google-play-services/libs/google-play-services.jar') compile (project(':actionbarsherlock')) { exclude(module: 'support-v4') } compile 'com.android.support:support-v4:18.0.+' }
解决了第二个问题,但仍然得到第一个问题多个dex文件定义错误.
请帮我,
谢谢,
p / s:我可以顺利地与Gradle同步,但是在运行时,它会出现上述错误.
我使用Android studio 0.5.5
编辑
ActionBarSherlock的build.gradle,它只有一个android-support-v4.jar:
dependencies { compile fileTree(dir: 'libs',include: '*.jar') }
像这样的setting.gradle:
include ':fitness',':google-play-services',':actionbarsherlock'
@Garbriele:我更新了新问题,显示了项目的build.gradle和主模块的build.gradle
build.gradle项目:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } }
编辑后的主模块的build.gradle:
dependencies { compile fileTree(dir: 'libs',include: '*.jar') compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line }
我在下面得到了这个错误:
好的,感谢@Garbriele的评论,我已经通过使用这个解决了这个问题:
repositories { mavenCentral() } dependencies { compile fileTree(dir: 'libs',include: '*.jar') compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line }
编辑2当我这样说:
repositories { mavenCentral() } dependencies { compile fileTree(dir: 'libs',include: '*.jar') compile 'com.google.android.gms:play-services:+' }
我现在想要的是如何通过Maven成功添加com.google.android.gms:play-services库,
UPDATE
完成以下步骤后:
>通过Maven将库放在main模块的build.gradle中:编译’com.google.android.gms:play-services:’
>重启Android Studio
>使用gradle同步项目
再也不会出现此错误.