简体   繁体   English

使用Spring和OAuth2的REST Android客户端错误DexArchiveMergerException:无法合并dex

[英]REST Android Client using Spring and OAuth2 Error DexArchiveMergerException: Unable to merge dex

I have a server running and I want to connect an android client to the server with spring's oauth2. 我有一个正在运行的服务器,我想用spring的oauth2将一个android客户端连接到该服务器。 I use Android Studio. 我使用Android Studio。 My problem is related to the gradle configurations, which I don't know how it should be. 我的问题与gradle配置有关,我不知道应该怎么做。

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

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. 我已经看到许多其他问题,但都遇到了同样的问题,我尝试了解决方案(例如添加multiDexEnabled true ,清理和重建项目等),但没有一个起作用。 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. 任何帮助,将不胜感激。


My build.gradle (Module: app) 我的build.gradle(模块:应用)

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'
}

My build.gradle (Project: RestClient) 我的build.gradle(项目: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
}

android { android {

dexOptions {
    preDexLibraries = false
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
packagingOptions
        {
            exclude 'AndroidManifest.xml'
            exclude 'META-INF/LICENSE'
            exclude 'META-IN F/NOTICE'
            exclude 'META-INF/DEPENDENCIES'
        }
defaultConfig {
    vectorDrawables.useSupportLibrary = true
    applicationId "com.support.project"
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}

} }

Try this it should work for your cause. 试试这个,它应该为您的事业工作。 Go through this link to understand why we should add this line of code multiDexEnabled true 通过此链接了解为什么我们应该添加此代码行multiDexEnabled true

I finally solved the problem. 我终于解决了问题。 There were two modules that were duplicate, so I had to exclude them from the Module build.gradle file. 有两个重复的模块,因此我不得不将它们从Module build.gradle文件中排除。 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'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex - Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex com.android.builder.dexing.DexArchiveMergerException:无法合并dex 5 - com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 5 Cloud Firestore:DexArchiveMergerException无法合并dex - Cloud Firestore : DexArchiveMergerException Unable to merge dex AndroidStudio DexArchiveMergerException:更新后无法合并dex - AndroidStudio DexArchiveMergerException: Unable to merge dex after update 错误:java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并 dex - Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Android中的“无法合并dex错误” - “Unable to merge dex error” in Android Rest Api调用使用Spring Oauth2给出错误400 - Rest Api call gives error 400 using Spring Oauth2 > java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex - > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 无法合并Dex错误:Android Studio 3.0 - Unable to merge Dex error: Android Studio 3.0 无法使用 Twitter OAuth 和 Spring Security OAuth2 Client 对应用程序进行身份验证 - Unable to authenticate application using Twitter OAuth with Spring Security OAuth2 Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM