集成新浪微博SDK,用gradle編譯時,報以下錯誤:java
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/sina/weibo/sdk/BuildConfig; 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)
緣由是weibosdkcore.jar裏面的BuildConfig.class,原本這個文件不該該存在於jar裏,不知微博的開發怎麼搞進去的。
解決方法很簡單:解包weibosdkcore.jar,刪除裏面的 BuildConfig.class,而後從新打包 jar。android
具體以下:
1. 解壓jar包:
jar xf weibosdkcore.jar
2. 刪除解壓後目錄裏面的com/sina/weibo/sdk/BuildConfig.class
3. 從新打包:
jar cvf weibosdkcore.jar *gradle