使用Gradle和Android Studio构建stORM时会出现dex错误

时间:2014-05-16 17:36:38

标签: android android-studio storm-gen android-storm

stORM https://code.google.com/p/storm-gen/

我在build.gradle中有以下内容

...
dependencies {
    compile 'com.android.support:support-v13:+'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.googlecode.libphonenumber:libphonenumber:6.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'log4j:log4j:1.2.16'
    compile 'org.slf4j:slf4j-log4j12:1.6.1'
}

android.applicationVariants.all { variant ->
    def aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")

    variant.javaCompile.options.compilerArgs += [
            "-processor", "com.turbomanage.storm.apt.MainProcessor",
            '-AandroidManifestFile=' + variant.processResources.manifestFile,
            '-s', aptOutput
    ]

    variant.javaCompile.source = variant.javaCompile.source.filter { p ->
        return !p.getPath().startsWith(aptOutput.getPath())
    }

    variant.javaCompile.doFirst {
        aptOutput.mkdirs()
    }
}
...

放入libs:

storm-api-0.97.jar
storm-apt-0.97.jar

在使用gradle assembleRelease构建时,我得到:

:app:dexRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexRelease'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /xyz/android/sdk/build-tools/19.0.1/dx --dex --output 
/xyz/code/studio/Myapp/app/build/dex/release 
/xyz/code/studio/Myapp/app/build/classes/release 
/xyz/code/studio/Myapp/app/build/dependency-cache/release 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/libphonenumber-6.0-abc2e51ec6ac0cb8f28ec86ee41a37511055f6ea.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/library-2.4.0-31f82b62b24973486e6bf5acdc255648bd6a567a.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/log4j-1.2.16-51a933677ad733ef5cca3cb304434fddd96c08ca.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/slf4j-api-1.6.1-a040969be47961e95d820688122f6e64c1ac6025.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/slf4j-log4j12-1.6.1-8c58ce04b54255044a79c495ab437e1d1837ca00.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/storm-api-0.97-5a13884740c461b336ce512036f4706f19544b0b.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/storm-apt-0.97-59dde234977ec5d0b6dadf5e7497cf4d6ccb1649.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/support-v13-19.1.0-dd8f989f7c1c7adbefa06c594c0cfc6cb6c75387.jar 
/xyz/code/studio/Myapp/app/build/pre-dexed/release/support-v4-19.1.0-155f54881a6e6cf88c81786a2d33043cfc538af3.jar
  Error Code:
2
  Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define   Lcom/example/storm/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)

命令gradle -q dependencies,仅显示

------------------------------------------------------------
Root project
------------------------------------------------------------

No configurations

我不确定问题是什么,有人吗?

1 个答案:

答案 0 :(得分:1)

它抱怨两个罐子带来了BuildConfig类(因为现在两个罐子的生成方式,将来会改变)。

您不需要API jar,只需要APT(实际上包含API类)。这将删除你的dex问题。

另一个建议是使用android-apt,它会让你的生活更简单!