Android 编译报Run with --stacktrace option to get the stack trace

Android开发在编译过程中经常会报类似如下的错误,突如其来经常会让我们不知所措。这时候最需要的就是静下心来,照着报错的提示排查问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\77.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\80.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\81.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\82.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\79.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\74.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\73.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\76.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\75.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\78.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\17.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\26.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\25.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\12.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\8.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\21.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\4.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\5.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\27.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\0.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\22.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\14.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\30.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\31.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\13.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\18.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\9.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\28.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\10.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\15.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\1.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\2.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\19.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\6.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\23.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\11.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\16.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\29.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\3.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\24.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\7.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\20.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\72.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: com.google.gson.FieldAttributes

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

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
39 actionable tasks: 15 executed, 24 up-to-date

Click and drag to move

Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.这句话是重点,但是说得不明不白的也不知道要怎么操作。

其实很简单,首先在Android Studio找到Terminal控制台(这个其实和CMD命令行控制台是一样的)

imgClick and drag to move

然后在控制台中输入如下指令,就可以重新编译debug版本,且带参数–stacktrace编译,如果编译失败会有失败的路径信息。

1
gradlew compileDebug --stacktrace

Click and drag to move

或者–info和–debug参数也用上会打印更多的log信息。

1
gradlew compileDebug --stacktrace --info --debug

Click and drag to move