У меня есть приложение Android, которое явно использует последнюю (v2.15. +) Версию библиотеки Amazon AWS, но также имеет зависимость от безбожно огромной библиотеки (netcdf4), которая, похоже, тянет собственная (старая) копия (v1.11.236) библиотеки Amazon, отличная от Android Java и вызывающая ошибки «Дубликат класса» при сборке.
Я знаю, что мне нужно как-то изменить build.gradle, чтобы он использует старую версию (v1.11.236) только для вещей, которые вытаскивает implementation group: 'edu.ucar', name: 'netcdf4', version: '4.6.11'
, но использует версию new (v2.15. +) для всего остального ... но я не уверен, как на самом деле сделать это.
Вещи, которые я пробовал до сих пор:
Вдохновленный ответом на другой вопрос , я попытался добавить следующее в конец блока «android {}» (в надежде, что он бесцеремонно удалит файлы, отличные от Android .jars, и позволит компилировать все без ошибок).
applicationVariants.all { variant ->
variant.getRuntimeConfiguration().exclude group: 'com.amazonaws', module: 'aws-java-sdk-core'
}
... к сожалению, это привело к тому, что Gradle syn c ошибка:
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve org.apache.httpcomponents:httpclient:4.5.1.
Show Details
Affected Modules: app
Мой текущий файл build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "pantherkitty.launchspotter"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
repositories {
mavenCentral()
maven {
url "https://artifacts.unidata.ucar.edu/repository/unidata-all/"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.amazonaws:aws-android-sdk-s3:2.15.+'
implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.15.+@aar') { transitive = true }
implementation ('com.amazonaws:aws-android-sdk-auth-userpools:2.15.+@aar') { transitive = true }
implementation group: 'edu.ucar', name: 'netcdf4', version: '4.6.11'
}
... и ошибки:
Executing tasks: [:app:assembleDebug] in project C:\src\Android\launchspotter
> Task :app:preBuild UP-TO-DATE
(...snip...)
> Task :app:checkDebugDuplicateClasses FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class com.amazonaws.AbortedException found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.AmazonClientException found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.AmazonServiceException found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.AmazonServiceException$ErrorType found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.AmazonWebServiceClient found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
(...snip...)
Duplicate class com.amazonaws.services.kms.AWSKMS found in modules jetified-aws-android-sdk-kms-2.15.2.jar (com.amazonaws:aws-android-sdk-kms:2.15.2) and jetified-aws-java-sdk-kms-1.11.236.jar (com.amazonaws:aws-java-sdk-kms:1.11.236)
Duplicate class com.amazonaws.services.kms.AWSKMSClient found in modules jetified-aws-android-sdk-kms-2.15.2.jar (com.amazonaws:aws-android-sdk-kms:2.15.2) and jetified-aws-java-sdk-kms-1.11.236.jar (com.amazonaws:aws-java-sdk-kms:1.11.236)
(...snip...)
Duplicate class com.amazonaws.services.s3.AmazonS3 found in modules jetified-aws-android-sdk-s3-2.15.2.jar (com.amazonaws:aws-android-sdk-s3:2.15.2) and jetified-aws-java-sdk-s3-1.11.236.jar (com.amazonaws:aws-java-sdk-s3:1.11.236)
Duplicate class com.amazonaws.services.s3.AmazonS3Client found in modules jetified-aws-android-sdk-s3-2.15.2.jar (com.amazonaws:aws-android-sdk-s3:2.15.2) and jetified-aws-java-sdk-s3-1.11.236.jar (com.amazonaws:aws-java-sdk-s3:1.11.236)
Duplicate class com.amazonaws.services.s3.AmazonS3Client$1 found in modules jetified-aws-android-sdk-s3-2.15.2.jar (com.amazonaws:aws-android-sdk-s3:2.15.2) and jetified-aws-java-sdk-s3-1.11.236.jar (com.amazonaws:aws-java-sdk-s3:1.11.236)
Duplicate class com.amazonaws.services.s3.AmazonS3Client$2 found in modules jetified-aws-android-sdk-s3-2.15.2.jar (com.amazonaws:aws-android-sdk-s3:2.15.2) and jetified-aws-java-sdk-s3-1.11.236.jar (com.amazonaws:aws-java-sdk-s3:1.11.236)
Duplicate class com.amazonaws.services.s3.AmazonS3Encryption found in modules jetified-aws-android-sdk-s3-2.15.2.jar (com.amazonaws:aws-android-sdk-s3:2.15.2) and jetified-aws-java-sdk-s3-1.11.236.jar (com.amazonaws:aws-java-sdk-s3:1.11.236)
(...snip...)
Duplicate class com.amazonaws.util.TimingInfoFullSupport found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.TimingInfoUnmodifiable found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.ValidationUtils found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.VersionInfoUtils found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.XMLWriter found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.XmlUtils found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
Duplicate class com.amazonaws.util.XpathUtils found in modules jetified-aws-android-sdk-core-2.15.2.jar (com.amazonaws:aws-android-sdk-core:2.15.2) and jetified-aws-java-sdk-core-1.11.236.jar (com.amazonaws:aws-java-sdk-core:1.11.236)
BUILD FAILED in 594ms
17 actionable tasks: 1 executed, 16 up-to-date