8.07.2015

Android Studio build error - Error:Android Dex: [...] Unable to execute DX

Error:Android Dex: [EdiLife] Unable to execute DX
Error:Android Dex: [EdiLife] com.android.dex.DexException: Multiple dex files define Lcom/google/android/gcm/GCMBaseIntentService;
Error:Android Dex: [EdiLife] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
Error:Android Dex: [EdiLife] at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
Error:Android Dex: [EdiLife] at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
Error:Android Dex: [EdiLife] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
Error:Android Dex: [EdiLife] at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
Error:Android Dex: [EdiLife] at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
Error:Android Dex: [EdiLife] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
Error:Android Dex: [EdiLife] at com.android.dx.command.dexer.Main.run(Main.java:230)
Error:Android Dex: [EdiLife] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Error:Android Dex: [EdiLife] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Error:Android Dex: [EdiLife] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Error:Android Dex: [EdiLife] at java.lang.reflect.Method.invoke(Method.java:606)
Error:Android Dex: [EdiLife] at org.jetbrains.android.compiler.tools.AndroidDxRunner.runDex(AndroidDxRunner.java:161)
Error:Android Dex: [EdiLife] at org.jetbrains.android.compiler.tools.AndroidDxRunner.main(AndroidDxRunner.java:294)
Error:Android Dex: [EdiLife] at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)

在Android Studio環境下Compiler 專案,結果跳出這惱人的錯誤,
後來查一查,"Multiple dex files define Lcom/google/android/gcm/GCMBaseIntentService"
發現是匯入到相同的兩個lib,因此package name有衝突,將一個移除後就可以正常Compiler了。