1

我正在尝试构建签名版本(发布版本),但出现以下错误

Duplicate zip entry [com/google/protobuf/d$1.class == com/google/protobuf/Any$1.class]

我试图清理、无效和删除 gradle 文件并重建它。还更新到最新版本的 gRPC 版本和 protobuf。也尝试了这个解决方案,但没有奏效。

这是我的 build.gradle (应用程序模块)文件

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
apply plugin: 'io.fabric'


ext {
    supportLibraryVersion = '27.1.1'
    grpcVersion = '1.13.1'
    googlePlayVersion = '15.0.1'
    firebaseCoreVersion = '16.0.1'
    firebaseDataBaseVersion = '16.0.1'
    firebaseAuthVersion = '16.0.2'
    firebaseFirestoreVersion = "17.0.1"
    fireUIVersion = '4.0.1'
    facebookAuthVersion = '4.34.0'
    protobufVersion = '3.6.0'
    butterKnifeVersion = '8.8.1'
    glideVersion = '4.7.1'
    retrofitVersion = '2.4.0'
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
       // app id
        targetSdkVersion 27
        versionCode 1
        versionName '1.0'
        multiDexEnabled true
        minSdkVersion 21
    }

    signingConfigs {
        release {
            storeFile file(project.properties.storeFile)
            storePassword project.properties.storePassword
            keyAlias project.properties.keyAlias
            keyPassword project.properties.keyPassword
        }
    }


    buildTypes {
        debug {
            minifyEnabled false

        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
        resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"

    }
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.6.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Implementing my  libraries
    implementation project(path: ':CircularProgressBar')

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'

    // Support libraries
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    implementation "com.android.support:support-annotations:$supportLibraryVersion"

    //PlayServices
    implementation "com.google.android.gms:play-services-auth:$googlePlayVersion"

    // FirebaseUI for Firebase Auth
    implementation "com.google.firebase:firebase-core:$firebaseCoreVersion"
    implementation "com.google.firebase:firebase-database:$firebaseDataBaseVersion"
    implementation "com.google.firebase:firebase-auth:$firebaseAuthVersion"
    implementation "com.google.firebase:firebase-firestore:$firebaseFirestoreVersion"
    implementation "com.firebaseui:firebase-ui-auth:$fireUIVersion"

    //FacebookAuth Login
    implementation "com.facebook.android:facebook-login:$facebookAuthVersion"

    //Jackson
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
    //Retrofit2
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    //SqlCipher
    implementation 'net.zetetic:android-database-sqlcipher:3.5.9@aar'

    //highlighter
    implementation 'com.xeoh.android:text-highlighter:1.0.2'

    //ButterKnife
    implementation "com.jakewharton:butterknife:$butterKnifeVersion"

    //Glide
    implementation "com.github.bumptech.glide:glide:$glideVersion"


    //SwipeReveal
    implementation "com.daimajia.swipelayout:library:1.2.0@aar"

    //JodaTime
    implementation 'joda-time:joda-time:2.10'
    //Gson
    implementation 'com.google.code.gson:gson:2.8.4'

    //Animation
    implementation 'at.wirecube:additive_animations:1.6.2'
    implementation 'com.wang.avi:library:2.1.3'

    //HorizontalCalendar
    implementation 'devs.mulham.horizontalcalendar:horizontalcalendar:1.3.4'


    // gRPC
    implementation "io.grpc:grpc-okhttp:$grpcVersion"
    implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
    implementation 'com.google.protobuf:protobuf-lite:3.0.1'
    implementation "io.grpc:grpc-stub:$grpcVersion"
    implementation 'javax.annotation:javax.annotation-api:1.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    protobuf "com.google.protobuf:protobuf-java:$protobufVersion"

    // OAuth2 for Google API
    implementation('com.google.auth:google-auth-library-oauth2-http:0.9.1') {
        exclude module: 'httpclient'
    }

    //Permissions
    implementation 'gun0912.ted:tedpermission:2.2.0'

    //String ratio search
    implementation 'me.xdrop:fuzzywuzzy:1.1.9'

    //Logger
    implementation 'com.orhanobut:logger:2.2.0'

    implementation 'com.intentfilter:android-permissions:0.1.7'
    // Annotation processors
    annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
    annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
    //multiDex
    // implementation 'com.android.support:multidex:1.0.3'

    // Tests
    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'



}

task copySecretKey(type: Copy) {
    def File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
    from secretKey.getParent()
    include secretKey.getName()
    into 'src/main/res/raw'
    rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)

apply plugin: 'com.google.gms.google-services'

职业后卫

-dontwarn com.google.common.**
-dontwarn com.google.api.client.**
-dontwarn com.google.protobuf.**
-dontwarn io.grpc.**
-dontwarn okio.**
-dontwarn com.google.errorprone.annotations.**
-keep class io.grpc.internal.DnsNameResolveProvider
-keep class io.grpc.okhttp.OkHttpChannelProvider

-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

-printmapping mapping.txt

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.**
-dontwarn okio.**
-dontwarn retrofit2.**
-dontwarn org.joda.convert.**
-dontwarn okhttp3.internal.platform.**
-ignorewarnings

详细运行过程错误:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Job failed, see logs for details
    at com.android.build.gradle.internal.transforms.ProGuardTransform.transform(ProGuardTransform.java:196)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 32 more
Caused by: java.io.IOException: Can't write [D:\...\app\build\intermediates\transforms\proguard\release\0.jar] (Can't read [D:\..\app\build\intermediates\transforms\desugar\release\1(;;;;;;**.class)] (Can't read [com] (Can't read [google] (Can't read [protobuf] (Can't read [Any$1.class] (Duplicate zip entry [com/google/protobuf/d$1.class == com/google/protobuf/Any$1.class]))))))
    at proguard.OutputWriter.writeOutput(OutputWriter.java:187)
    at proguard.OutputWriter.execute(OutputWriter.java:79)
    at proguard.ProGuard.writeOutput(ProGuard.java:427)
    at proguard.ProGuard.execute(ProGuard.java:175)
    at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:61)
    at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:253)
    at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:63)
    at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:173)
    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)
    ... 1 more
4

1 回答 1

1

问题是 Firestore 依赖项添加了额外的 protobuf lite 依赖项

    implementation("com.google.firebase:firebase-firestore:$firebaseFirestoreVersion") {
    exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
    }

排除附加部分将解决问题。

要检查 Android Studio 终端中的冲突依赖,请编写

gradlew app:dependencies 

并且一次不会添加更多的验证。

于 2018-07-06T11:56:47.373 回答