Android:处理gradle

时间:2017-09-09 09:04:46

标签: android android-gradle dex

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

enter image description here

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

enter image description here

首先我想,问题可能是对于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
}
}

1 个答案:

答案 0 :(得分:1)

最后,经过长时间的实验,我解决了这个问题。

问题transformClassesWithDexForRelease'在发布版本时即将发布。经过一个小小的研究后,我发现这个问题与jar /库版本不匹配,jar /库重复,冲突等多种原因有关。

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

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

然后我最终从回收视图中排除了这两个库,并且能够构建应用程序。

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