Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

java - Android build fails over com.android.dex.DexException: Multiple dex files define Landroid/support

In Android project were team primarily still uses Eclipse were added some 3rd parties libs, then Android Studio fails to run on device anf when running gradle build there is error:

:preDexDebug                      
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.umeng.socialize.bean.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.umeng.socialize.bean.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

And so on warning: Ignoring InnerClasses attribute 10 to 20 times for different files

(UPDATE these warnings seem to be older issue, see Dx warning issues with latest Android SDK dated Nov 2 '11; also in Many issues after upgrading to Android Studio 1.0)

warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.tencent.mm.sdk.b.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

:dexDebug                    
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: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)

:dexDebug FAILED          

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:Program FilesJavajdk1.8.0_05injava.exe'' finished with no
n-zero exit value 2

* Try:        
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED  

Tried with

buildToolsVersion "19.1.0"
compileSdkVersion 19

and

buildToolsVersion "22"
compileSdkVersion 22

and

buildToolsVersion "21.1.2"
compileSdkVersion 21

for both

compile 'com.android.support:appcompat-v7:19.0.+'

and compile 'com.android.support:appcompat-v7:21.0.+'

Eclipse ADT has no problem. How to overcome with gradle / Android Studio?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thanks to Guillermo Merino for hint. Yes there is android-support-v4.jar there.

Solved with exclude as

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar', exclude: 'android-support-*.jar')
    //...
}

see also


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...