REST Android 客户端使用 Spring 和 OAuth2 错误 DexArchiveMergerException:无法合并 dex [英] REST Android Client using Spring and OAuth2 Error DexArchiveMergerException: Unable to merge dex

查看:63
本文介绍了REST Android 客户端使用 Spring 和 OAuth2 错误 DexArchiveMergerException:无法合并 dex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器正在运行,我想使用 spring 的 oauth2 将一个 android 客户端连接到服务器.我使用安卓工作室.我的问题与gradle配置有关,我不知道应该如何.

I have a server running and I want to connect an android client to the server with spring's oauth2. I use Android Studio. My problem is related to the gradle configurations, which I don't know how it should be.

问题:当我运行应用程序时,出现此错误:

Problem: When I run the app, I get this error:

Error:Execution failed for task':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我已经看到许多其他问题与相同的问题,我尝试了解决方案(例如添加 multiDexEnabled true、清理和重建项目等),但没有一个奏效.我认为问题是由这两个依赖引起的:

I have seen many other questions with the same problem, I tried the solutions (like adding multiDexEnabled true, clean and rebuild the project etc.) but none of them worked. I think that the problem is caused because these two dependencies:

implementation 'org.springframework.security.oauth:spring-security-oauth2:2.2.0.RELEASE'
implementation 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'

可能有一些常见的罐子什么的.任何帮助将不胜感激.

might have some common jars or something. Any help would be appreciated.

我的 build.gradle(模块:app)

My build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "readinghood.restclient"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/spring.tooling'
        exclude 'META-INF/spring.handlers'
        exclude 'META-INF/spring.schemas'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    implementation 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
    implementation 'org.springframework.security.oauth:spring-security-oauth2:2.2.0.RELEASE'
    implementation 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
}

我的 build.gradle(项目:RestClient)

My build.gradle (Project: RestClient)

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'http://repo.spring.io/libs-release' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

推荐答案

我终于解决了这个问题.有两个模块是重复的,所以我不得不从 Module build.gradle 文件中排除它们.我必须做的是:

I finally solved the problem. There were two modules that were duplicate, so I had to exclude them from the Module build.gradle file. What I had to do was:

compile('org.springframework.android:spring-android-rest-template:2.0.0.M3') {
    exclude module: 'spring-android-core'
}

compile('org.springframework.security.oauth:spring-security-oauth2:2.3.0.RC1'){
    exclude module: 'spring-web'
}

这篇关于REST Android 客户端使用 Spring 和 OAuth2 错误 DexArchiveMergerException:无法合并 dex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆