REST Android 客户端使用 Spring 和 OAuth2 错误 DexArchiveMergerException:无法合并 dex
REST Android Client using Spring and OAuth2 Error DexArchiveMergerException: Unable to merge dex
我有一个服务器 运行ning,我想用 spring 的 oauth2 将一个 android 客户端连接到服务器。我使用 Android Studio。我的问题与 gradle 配置有关,我不知道应该如何配置。
问题:当我 运行 应用程序时,出现此错误:
Error:Execution failed for task':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我已经看到许多其他问题与相同的问题,我尝试了解决方案(如添加 multiDexEnabled true
、清理并重建项目等),但其中 none 有效。我认为问题是由这两个依赖项引起的:
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(模块: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)
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 {
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 {
}
}
试试这个,它应该对你有用。 Go through this link明白为什么要加上这行代码multiDexEnabled true
我终于解决了这个问题。有两个重复的模块,因此我不得不将它们从 Module build.gradle 文件中排除。我必须做的是:
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'
}
我有一个服务器 运行ning,我想用 spring 的 oauth2 将一个 android 客户端连接到服务器。我使用 Android Studio。我的问题与 gradle 配置有关,我不知道应该如何配置。
问题:当我 运行 应用程序时,出现此错误:
Error:Execution failed for task':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我已经看到许多其他问题与相同的问题,我尝试了解决方案(如添加 multiDexEnabled true
、清理并重建项目等),但其中 none 有效。我认为问题是由这两个依赖项引起的:
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(模块: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)
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 {
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 {
}
}
试试这个,它应该对你有用。 Go through this link明白为什么要加上这行代码multiDexEnabled true
我终于解决了这个问题。有两个重复的模块,因此我不得不将它们从 Module build.gradle 文件中排除。我必须做的是:
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'
}