Android:处理来自 gradle 的 transformClassesWithDexForRelease 错误
Android: Handle transformClassesWithDexForRelease error from gradle
我通过将其添加到 gradle 依赖项中来使用第 3 方库。但不幸的是,我在创建最终版本时遇到了一些 dex 错误。(下图)
在 gradlew app:dependancies 命令中,我得到了库的以下层次结构。
首先我认为,问题可能出在 recycleView.So 我尝试从该库中排除 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/library 版本不匹配、jar/library 重复、冲突等
检查依赖层次结构(gradlew app:dependencies)后,我发现我使用的第 3 方库正在使用其他一些更高版本的库。所以我只是获取库代码并在我的应用程序中实现它,将适当的依赖库版本放在 gradle 中。
它以某种方式解决了问题,但没有解决全部问题。同样的问题transformClassesWithDexForRelease'
。然后我再次检查层次结构,发现只有 support-annotations
和 support-v4
几乎都是图书馆的主要原因也是这里的主要原因。
最后我从 Recycle-View 中排除了这两个库并能够构建应用程序。
compile ('com.android.support:recyclerview-v7:22.2.0'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
}
我通过将其添加到 gradle 依赖项中来使用第 3 方库。但不幸的是,我在创建最终版本时遇到了一些 dex 错误。(下图)
在 gradlew app:dependancies 命令中,我得到了库的以下层次结构。
首先我认为,问题可能出在 recycleView.So 我尝试从该库中排除 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/library 版本不匹配、jar/library 重复、冲突等
检查依赖层次结构(gradlew app:dependencies)后,我发现我使用的第 3 方库正在使用其他一些更高版本的库。所以我只是获取库代码并在我的应用程序中实现它,将适当的依赖库版本放在 gradle 中。
它以某种方式解决了问题,但没有解决全部问题。同样的问题transformClassesWithDexForRelease'
。然后我再次检查层次结构,发现只有 support-annotations
和 support-v4
几乎都是图书馆的主要原因也是这里的主要原因。
最后我从 Recycle-View 中排除了这两个库并能够构建应用程序。
compile ('com.android.support:recyclerview-v7:22.2.0'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
}