【问题标题】:Unity proguard: Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'Unity proguard:任务“:transformClassesAndResourcesWithProguardForRelease”执行失败
【发布时间】:2019-09-29 03:59:29
【问题描述】:

我正在将 Unity 2018.1.6f1 与 Google Play 服务和 Startapp sdk 一起使用。现在我需要集成 Admob。但我无法构建。

由于我面临 DEX 限制,我在构建设置中切换到 Proguard,并且 Admob 建议这样做。

Unity 控制台消息片段:

stderr[
Note: there were 269 duplicate class definitions.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task 
':transformClassesAndResourcesWithProguardForRelease'.

然后是长长的列表 注意:程序类的重复定义

我应该如何修改“mainTemplate.gradle”或“proguard-user.txt”文件来进行构建?还是应该?

【问题讨论】:

    标签: android unity3d gradle duplicates proguard


    【解决方案1】:

    当您在启用 minify 的情况下构建发布时,您需要将异常放入您的 proguard 文件中。这些异常完全取决于您在应用程序构建 gradle 文件中使用的实现。例如,这个实现:

    dependencies {
    
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    
    //added these 2 lines to remove All com.android.support libraries must use the exact
    // same version specification warning; from 26 to 28
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    
    //implementation 'com.google.android.gms:play-services-location:16.0.0'
    //implementation 'com.google.android.gms:play-services-places:16.0.0'
    
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
    
    // Google
    //implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    
    
    // Firebase
    implementation 'com.google.firebase:firebase-analytics:16.3.0'
    implementation 'com.google.firebase:firebase-database:16.0.6'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-config:16.1.3'
    implementation 'com.google.firebase:firebase-appindexing:17.1.0'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    
    implementation 'com.google.android.gms:play-services-appinvite:16.1.0'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.android.gms:play-services-ads:17.1.3'
    
    
    // Firebase UI
    implementation 'com.firebaseui:firebase-ui-database:3.0.0'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    
    // firebase needs this needs to be version 1.1.1 firebase depends on
    // a mismatch - 1.0.0 & 1.1.1
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    
    // retrofit, gson
    implementation 'com.squareup.okio:okio:1.13.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.0.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
    
    
    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'
    
    implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
    
    //from the quick start
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    
    implementation('com.google.api-client:google-api-client-android:1.25.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    
    implementation('com.google.apis:google-api-services- 
    sheets:v4-rev553-1.25.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation "org.jetbrains.kotlin:kotlin-stdlib- 
    jdk7:$kotlin_version"
    
    }
    

    在 proguard 文件中需要这个来构建一个版本:

     # my stuff below
     -dontnote retrofit2.Platform
     # Platform used when running on Java 8 VMs. Will not be 
      used at runtime.
     -dontwarn retrofit2.Platform$Java8
     # Retain generic type information for use by reflection by 
     converters and adapters.
     #-keepattributes Signature
     # Retain declared checked exceptions for use by a Proxy 
     instance.
     #-keepattributes Exceptions
    
     -dontwarn okio.**
    
     # Needed by google-api-client to keep generic types and 
     @Key annotations accessed via reflection
     -keepclassmembers class * {
     @com.google.api.client.util.Key <fields>;
     }
    
     #-keepattributes 
     Signature,RuntimeVisibleAnnotations,AnnotationDefault
    
     #-dontnote org.apache.**
     #-dontwarn java.lang.**
    
     -dontwarn com.google.errorprone.annotations.**
    
     -keep public class com.google.common.** { public *; }
     -dontwarn com.google.common.**
    
     -dontnote android.net**
     -dontwarn com.google.firebase.appindexing.internal.**
    

    所以要做的就是在日志中找到重复项和错误,并为日志中的每个警告添加一个 proguard 条目

    【讨论】:

    • 这是我的控制台错误:stderr[ Note: there were 269 duplicate class definitions. Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'. ] stdout[ Note: duplicate definition of program class [com.google.android.gms.actions.ItemListIntents] 这是我的 proguard-user.txt:-dontwarn com.google.android.gms.** 但我仍然收到错误
    • 269 个重复的类定义中的任何一个都可能导致它失败;你的 proguard 文件中可能需要更多内容。
    • 我已经像-dontwarn com.google.android.gms.common.zza这样将所有警告文件添加到proguard文件中,但没有效果
    • 如果错误永远不会改变,因为“无效”意味着 gradle 可能在错误的位置寻找 proguard 文件。仅将其作为测试# bad #-ignorewarnings #-keep class * { # public private *; #}
    猜你喜欢
    • 1970-01-01
    • 2020-07-30
    • 2017-05-18
    • 2020-03-07
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 2016-05-02
    相关资源
    最近更新 更多