Я использую Gradle версии 3.1.2 с инструментами сборки версии 27.0.3.Когда я собираю APK с помощью proguard, после обновления до версии 3.2.0 / 3.2.1 gradle будет выдано сообщение об ошибке:
Дублирующая запись jar [com / rometools / utils / Alternatives.class].
И часть сообщения об ошибке:
org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95) ... 30 more Caused by: java.io.IOException: Can't write [C:\PATH\AppName\app\build\intermediates\transforms\proguard\debug\0.jar] (Can't read [C:\PATH\AppName\app\build\intermediates\transforms\FirebasePerformancePlugin\debug\36(;;;;;;;**.class)] (Can't read [com] (Can't read [rometools] (Can't read [utils] (Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class])))))) at proguard.OutputWriter.writeOutput(OutputWriter.java:202) at proguard.OutputWriter.execute(OutputWriter.java:89) at proguard.ProGuard.writeOutput(ProGuard.java:515) at proguard.ProGuard.execute(ProGuard.java:210) at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:64) at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:262) at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:65) at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:176) at com.android.builder.tasks.Job.runTask(Job.java:47) at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41) at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:282) Caused by: java.io.IOException: Can't read [C:\PATH\AppName\app\build\intermediates\transforms\FirebasePerformancePlugin\debug\36(;;;;;;;**.class)] (Can't read [com] (Can't read [rometools] (Can't read [utils] (Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class]))))) at proguard.InputReader.readInput(InputReader.java:214) at proguard.InputReader.readInput(InputReader.java:184) at proguard.OutputWriter.writeOutput(OutputWriter.java:191) ... 10 more Caused by: java.io.IOException: Can't read [com] (Can't read [rometools] (Can't read [utils] (Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class])))) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:81) at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53) at proguard.InputReader.readInput(InputReader.java:210) ... 12 more Caused by: java.io.IOException: Can't read [rometools] (Can't read [utils] (Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class]))) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:81) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:77) ... 14 more Caused by: java.io.IOException: Can't read [utils] (Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class])) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:81) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:77) ... 15 more Caused by: java.io.IOException: Can't read [Alternatives.class] (Duplicate jar entry [com/rometools/utils/Alternatives.class]) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:81) at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:77) ... 16 more Caused by: java.io.IOException: Duplicate jar entry [com/rometools/utils/Alternatives.class] at proguard.io.ZipOutput.createOutputStream(ZipOutput.java:155) at proguard.io.ZipOutput.createOutputStream(ZipOutput.java:120) at proguard.io.JarWriter.createOutputStream(JarWriter.java:137) at proguard.io.FilteredDataEntryWriter.createOutputStream(FilteredDataEntryWriter.java:111)
Согласно сообщению об ошибке, ошибка связана с двумя библиотеками: firebase и rome.Поэтому я попытался удалить одну из библиотек и снова собрать APK с помощью proguard, после чего он будет успешно собран без ошибок.Для проверки ошибки, связанной с proguard, я попытался собрать без proguard, которая также будет успешно скомпилирована.
Ошибка возникает при сборке с proguard, при одновременном использовании библиотек firebase и rome и использовании версии gradle3.2.0 / 3.2.1.
Понятия не имею, чтобы решить проблему.Кто-нибудь знал, как решить проблему?Заранее спасибо.
Обновление:
build.gradle из: app
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "testing.testing.testproguard"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
}
release {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
}
}
// Using gradle plugin 3 you need to specify flavor dimensions.
flavorDimensions 'buildType'
// Always show the result of every unit test, even if it passes.
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
packagingOptions {
exclude 'META-INF/rxjava.properties'
pickFirst 'rome.properties'
pickFirst 'rome-utils-*.jar'
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/mock/java/'] } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// For support firebase on API 16-20(android 4.1-4.4.4)
implementation "com.android.support:multidex:$rootProject.multidexVersion"
// Firebase
implementation "com.google.firebase:firebase-core:$rootProject.firebaseVersion"
implementation "com.google.firebase:firebase-ads:$rootProject.firebaseAdsVersion"
implementation "com.google.firebase:firebase-perf:$rootProject.firebasePerfVersion"
// jdom (for support ROME)
implementation "org.jdom:jdom2:$rootProject.jdomVersion"
// slf4j (for support ROME)
implementation "org.slf4j:slf4j-api:$rootProject.slf4jVersion"
implementation "org.slf4j:slf4j-nop:$rootProject.slf4jVersion"
// ROME
implementation "com.rometools:rome:$rootProject.romeVersion"
}
// Firebase SDKs
apply plugin: 'com.google.gms.google-services'
build.gradle проекта
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
// for Firebase SDK
maven { url "https://maven.google.com" } // necessary for Android API 26
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// for Google Analytics
classpath 'com.google.gms:google-services:4.2.0'
// for Firebase Performance Monitoring
classpath 'com.google.firebase:firebase-plugins:1.1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
jcenter {
url "https://jcenter.bintray.com/"
}
maven {
url "https://repo1.maven.org/maven2"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
// Sdk and tools
minSdkVersion = 16
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = '28.0.3'
// App dependencies
multidexVersion = '1.0.3'
firebaseVersion = '16.0.6'
firebaseAdsVersion = '17.1.2'
firebasePerfVersion = '16.2.2'
jdomVersion = '2.0.6'
slf4jVersion = '1.7.25'
romeVersion = '1.12.0'
}
proguard-rules.pro file
-keep class android.support.v4.widget.DrawerLayout { *; }
-keep class android.support.test.espresso.IdlingResource { *; }
-keep class com.google.common.base.Preconditions { *; }
# For Guava:
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe
# Proguard rules that are applied to your test apk/code.
-ignorewarnings
# streamsupport
-keep class java8.** { *; }
-dontwarn java8.**
# rome
-dontwarn com.rometools.rome.**
-keep class com.rometools.** { *; }
-keep interface com.rometools.** { *; }
-repackageclasses
-allowaccessmodification