【问题标题】:Ormlite Multiple dex with Android StudioOrmlite Multiple dex 与 Android Studio
【发布时间】:2014-05-09 20:50:14
【问题描述】:

我刚刚在我的 android 项目中添加了Ormlite,但出现以下错误:

Error:Execution failed for task ':AgCelence:dexDebug'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /my/home/path/apps/Android/sdk/build-tools/19.0.3/dx --dex --output /my/home/path/workspace/my/project/path/build/dex/debug
    /my/home/path/workspace/my/project/path/build/classes/debug
    /my/home/path/workspace/my/project/path/build/dependency-cache/debug
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/butterknife-4.0.1-5a7b9ed780d5fa0603abb39fdc181c512fa9b1c3.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/classes-1a1090f3a59a705e7e344c2ae25b0c5f88f721d6.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/classes-edaf04f87f77ab0f4105648ab63bdcd09694eb0d.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/dagger-1.2.1-212943657b662e900a542e2d88abbd5fdcaf8d33.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/flurry-3.4.0-6b0fea36afcc1a3b450e16a58c03d9869b754f02.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/gson-2.2.4-3d9d795bb76d7955fd85ce17556cc505830bd1f7.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/javax.inject-1-e8f1138f6c9c0f8271805129c6151ff544950b34.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/ormlite-android-4.9-5eaa7600b65948820881b78781d30698f1033ff5.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/ormlite-core-4.9-25352cf2f40621c7a86eff7f10a40c6a66cdf76a.jar
    /my/home/path/workspace/my/project/path/build/pre-dexed/debug/support-v4-19.1.0-8212ff791cfaeb109a87aa612d03eec280361949.jar
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/j256/ormlite/dao/CloseableIterable;
        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)

我的“build.gradle”:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.3'
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName '0.1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':porquenaotoolkit')
    compile project(':libraries:twoway-view:TwoWayView')
    compile 'com.android.support:support-v4:19.+'
    compile 'com.squareup.dagger:dagger:1.2.+'
    compile 'com.jakewharton:butterknife:4.0.+'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.j256.ormlite:ormlite-android:4.9'
}

porquenaotoolkit build.gradle:

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.jakewharton:butterknife:4.0.+'
    compile 'com.google.code.gson:gson:2.2.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

TwoWayView build.gradle:

apply plugin: 'android-library'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:18.0.+'
}

android {
    compileSdkVersion 16
    buildToolsVersion "19.0.0"
}

有人知道如何解决这个问题吗???如果我从 build.gradle 中删除 compile 'com.j256.ormlite:ormlite-android:4.9' 行,则不会出现问题,但我想使用这个库,并且我想使用 gradle 来管理它......

【问题讨论】:

    标签: android android-studio ormlite dex


    【解决方案1】:

    我解决了我自己的问题,将build.gradle 的行从:

    compile 'com.android.support:support-v4:19.+'
    compile 'com.j256.ormlite:ormlite-android:4.9'
    

    到:

    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    

    并将 TwoWayView build.gradle 的行从:

    buildToolsVersion "19.0.0"
    compile 'com.android.support:support-v4:18.0.+'
    

    到:

    buildToolsVersion "19.0.3"
    compile 'com.android.support:support-v4:19.1.0'
    

    看来是不同支持库jars文件的问题...可惜Android Studio没有解决多个dex文件问题...我看到很多这种类型的问题。

    【讨论】:

    • 这个特殊问题是由于 ormlite:android 依赖于 ormlite:core 两者都定义了同一个类。你可以在这里看到它:search.maven.org/…
    • @Goddchen 我认为这是一个 gradle 错误。我们没有什么可做的。
    • 嘿,只是想让你知道我通过使用 4.48 版的 ormlite-android 工件解决了这个问题。该特定版本中似乎不存在该问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多