Unity proguard:任务“:transformClassesAndResourcesWithProguardForRelease”的执行失败

时间:2019-05-11 14:25:47

标签: android unity3d gradle duplicates proguard

我正在将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”文件以进行构建?还是我?

1 个答案:

答案 0 :(得分:0)

在构建启用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条目