我正在通过在gradle依赖项中添加一个第三方库来使用它。但不幸的是,创建最终版本时出现了一些dex错误。(下图)

android - Android:处理gradle中的transformClassesWithDexForRelease错误-LMLPHP

在gradlew app:dependancies命令中,我获得了库的以下层次结构。

android - Android:处理gradle中的transformClassesWithDexForRelease错误-LMLPHP

首先我认为问题可能出在recycleView上,所以我尝试从该库中排除recycleView模块,例如:

compile ('com.github.woxthebox:draglistview:1.4.7'){
        exclude module: 'recyclerview'
    }


但是什么也没发生。

谁知道,如何解决这种问题。还是从该库中排除什么来解决该dex问题?

编辑

build.gradle

apply plugin: 'com.android.library'

dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':FoundationServices:com.beeonics.android.fs.analytics')
compile project(':com.beeonics.android.application.gaf')
compile project(':com.beeonics.android.catalog')
compile project(':FoundationServices:com.beeonics.android.category')
compile project(':com.beeonics.android.consumeraccount')
compile project(':com.beeonics.android.core')
compile project(':FoundationServices:com.beeonics.android.location')
compile project(':com.beeonics.android.mediasharing')
compile project(':FoundationServices:com.beeonics.android.fs.notification')
compile project(':com.beeonics.android.product.catalog')
compile project(':com.beeonics.android.schedule')
compile project(':com.beeonics.android.services')
compile project(':FoundationServices:com.beeonics.android.store')
compile project(':FoundationServices:com.beeonics.android.fs.barcode')
compile project(':FoundationServices:com.beeonics.android.fs.map')
compile project(':google-play-services_lib')
compile project(':beeonics-mfc-android-contacts')
compile 'com.github.woxthebox:draglistview:1.4.7'

//compile 'com.android.support:cardview-v7:+'
//compile 'com.android.support:recyclerview-v7:+'

//acra
compile ('ch.acra:acra:4.9.2'){
    exclude group: 'com.android.support'
}

//compile 'com.android.support:appcompat-v7:22.2.0'

compile ('com.android.support:design:22.2.0'){
    exclude module: 'support-v4'
}

compile ('com.stripe:stripe-android:4.1.1'){
    exclude group: 'com.android.support'
}

// Retrofit stuffs
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'org.apache.commons:commons-lang3:3.6'
// JSON Parsing
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'

}

android {
compileSdkVersion 22
buildToolsVersion "25.0.0"
enforceUniquePackageName = false
sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-
    types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/...
    which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
dexOptions {
    preDexLibraries = false
}
}

最佳答案

经过长时间的试验,我终于解决了这个问题。

transformClassesWithDexForRelease'问题在发行版发行时出现。经过少量研究后,我发现此问题与多个原因有关,例如jar /库版本不匹配,jar /库重复,冲突等。

在检查依赖关系层次结构(gradlew app:dependencies)之后,我发现我使用的第3方库正在使用其他一些具有更高版本的库。因此,我只是将库代码并在应用程序中实现,并在gradle中放入了适当的依赖库版本。

它以某种方式解决了,但并没有解决整个问题。相同的问题transformClassesWithDexForRelease'。然后,我再次检查层次结构,发现只有support-annotationssupport-v4几乎都出现在几乎库中,这也是主要原因。

最后,我从Recycle-View中排除了这两个库,并能够构建该应用程序。

compile ('com.android.support:recyclerview-v7:22.2.0'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
}

关于android - Android:处理gradle中的transformClassesWithDexForRelease错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46128979/

10-12 15:37