サイズを考慮して、別の動的機能 (モジュール) に分割することにしたサードパーティの aar ファイルがあります。メインアプリと動的モジュールの両方com.google.code.gson:gson
が、依存関係を削除した同じモジュールにあったときに使用されてgson
いますが、現在、メインモジュールがそれを必要としています。
プロジェクトのビルドは問題ありませんが、バンドルをビルドしようとすると、
「プログラムの種類は既に存在します: com.google.gson.FieldNamingPolicy$5」エラー
モジュールの gradle から gson を除外しようとしました。依存関係と Android セクションの両方で、うまくいきませんでした。これはサードパーティの aar であるため、そのコードや依存関係にはアクセスできません。
メインアプリグラドル:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
mavenCentral()
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 26
versionCode 91
versionName "1.1.91"
multiDexEnabled true
}
buildTypes {
debug {
versionNameSuffix "-D"
matchingFallbacks = ['debug']
}
release {
matchingFallbacks = ['release']
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
pickFirst 'META-INF/license.txt'
pickFirst 'META-INF/DEPENDENCIES'
}
dexOptions {
javaMaxHeapSize "2g"
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "permissions"
productFlavors {
}
dynamicFeatures = [":dynamic_feature"]
}
dependencies {
implementation files('libs/gcm.jar')
//...
implementation 'com.google.code.gson:gson:2.8.2'
//...
}
apply plugin: 'com.google.gms.google-services'
動的機能グラドル:
apply plugin: 'com.android.dynamic-feature'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
//DOES NOT RESOLVE THE PROBLEM
all*.exclude group: 'com.google.gson'
all*.exclude group: 'com.google.code.gson'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':myapp')
//...
implementation files('libs/sdk.3rd-party.aar')
configurations {
//DOES NOT RESOLVE THE PROBLEM
all*.exclude group: 'com.google.gson'
all*.exclude group: 'com.google.code.gson'
}
}
エラー:
org.gradle.execution.MultipleBuildFailures: ビルドが 1 回失敗して完了しました。... 原因: java.lang.RuntimeException: com.android.build.api.transform.TransformException: メイン dex リストの生成中にエラーが発生しました: dex アーカイブのマージ中にエラーが発生しました: プログラムの種類が既に存在しています: com.google.gson.FieldNamingPolicy $5