Problems compiling an Android app in release mode with proguard enabled

I am trying to compile an Android application using proguard, but I am getting the following errors and don’t know how to fix them. Does anyone have an idea? In debug mode, everything compiles fine ...

Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver] Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory] Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException] Note: duplicate definition of library class [org.apache.http.params.HttpParams] Note: duplicate definition of library class [android.net.http.SslCertificate$DName] Note: duplicate definition of library class [android.net.http.SslError] Note: duplicate definition of library class [android.net.http.SslCertificate] Note: android.support.v4.app.NotificationCompatJellybean accesses a declared field 'title' dynamically Maybe this is program field 'android.support.v4.app.NotificationCompat$Action { java.lang.CharSequence title; }' Maybe this is program field 'android.support.v7.appcompat.R$attr { int title; }' Maybe this is program field 'android.support.v7.appcompat.R$id { int title; }' Maybe this is program field 'android.support.v7.mediarouter.R$attr { int title; }' Maybe this is program field 'android.support.v7.mediarouter.R$id { int title; }' Maybe this is program field 'com.facebook.share.internal.VideoUploader$UploadContext { java.lang.String title; }' Maybe this is program field 'com.facebook.share.model.GameRequestContent { java.lang.String title; }' Maybe this is program field 'com.facebook.share.model.GameRequestContent$Builder { java.lang.String title; }' Maybe this is program field 'com.google.android.gms.games.internal.player.PlayerColumnNames { java.lang.String title; }' Maybe this is program field 'com.google.android.gms.vision.barcode.Barcode$ContactInfo { java.lang.String title; }' Maybe this is program field 'com.google.android.gms.vision.barcode.Barcode$UrlBookmark { java.lang.String title; }' Maybe this is program field 'com.google.api.client.util.PemReader$Section { java.lang.String title; }' Maybe this is program field 'com.android.app.R$attr { int title; }' Maybe this is program field 'com.android.app.R$id { int title; }' Maybe this is program field 'com.android.app.adapter.InAppListItem { java.lang.String title; }' Maybe this is library field 'android.R$attr { int title; }' Maybe this is library field 'android.R$id { int title; }' Maybe this is library field 'android.app.Notification$Action { java.lang.CharSequence title; }' Maybe this is library field 'android.preference.PreferenceActivity$Header { java.lang.CharSequence title; }' Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpRequestInitializer Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpExecuteInterceptor Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.GenericUrl Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpResponse Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.util.GenericData Warning:library class com.google.api.client.auth.oauth2.TokenResponse depends on program class com.google.api.client.json.GenericJson Warning:library class com.google.api.client.auth.oauth2.TokenResponse depends on program class com.google.api.client.util.GenericData Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.webtoken.JsonWebSignature$Header Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.JsonFactory Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.webtoken.JsonWebToken$Payload Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.json.webtoken.JsonWebToken$Payload Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.json.GenericJson Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.util.GenericData Warning:library class com.google.api.client.auth.openidconnect.IdTokenVerifier depends on program class com.google.api.client.util.Clock Warning:library class com.google.api.client.auth.openidconnect.IdTokenVerifier$Builder depends on program class com.google.api.client.util.Clock Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestExecutor' Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestInterceptorList' Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpResponseInterceptorList' Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.SyncBasicHttpContext' Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.util.EntityUtils' Note: there were 2 references to unknown classes. You should check your configuration for typos. (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass) Note: there were 112 library classes explicitly being kept. You don't need to keep library classes; they are already left unchanged. (http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass) Note: there were 16 unresolved dynamic references to classes or interfaces. You should check if you need to specify additional program jars. (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass) Note: there were 4 accesses to class members by means of introspection. You should consider explicitly keeping the mentioned class members (using '-keep' or '-keepclassmembers'). (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember) Warning:there were 146 instances of library classes depending on program classes. You must avoid such dependencies, since the program classes will be processed, while the library classes will remain unchanged. (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency) Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. :app:transformClassesAndResourcesWithProguardForRelease FAILED Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. > java.io.IOException: Please correct the above warnings first. 

My Gradle file is as follows:

 apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 'Google Inc.:Google APIs:23' buildToolsVersion "23.0.1" defaultConfig { applicationId "com.test.app" minSdkVersion 17 targetSdkVersion 21 versionCode 240 versionName "2.4.0" // Enabling multidex support. multiDexEnabled true } buildTypes { release { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android.txt') proguardFile 'proguard-app.txt' } } } repositories { mavenCentral() } dependencies { compile 'com.google.http-client:google-http-client-gson:1.20.0' compile 'com.google.code.gson:gson:2.4' compile "com.android.support:appcompat-v7:23.1.1" compile 'com.google.android.gms:play-services:8.3.0' compile 'com.facebook.android:facebook-android-sdk:4.7.0' compile 'com.android.support:support-v13:23.1.0' compile files('libs/google-api-client-1.18.0-rc.jar') compile files('libs/google-api-client-android-1.18.0-rc.jar') compile files('libs/google-http-client-android-1.18.0-rc.jar') compile files('libs/AudienceNetwork.jar') } 

and here is the proguard-app.txt file of my proguard:

 # This is a configuration file for ProGuard. # http://proguard.sourceforge.net/index.html#manual/usage.html -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.view.View { public <init>(android.content.Context); public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); public void set*(...); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class * extends android.content.Context { public void *(android.view.View); public void *(android.view.MenuItem); } -keepclassmembers class * implements android.os.Parcelable { static ** CREATOR; } -keepclassmembers class **.R$* { public static <fields>; } -keepclassmembers class * { @android.webkit.JavascriptInterface <methods>; } -keepattributes Exceptions,InnerClasses,Signature -keep class com.google.api.client.** -keepclassmembers class com.google.api.client.** { *; } -keep class com.google.android.gms.** -keepclassmembers class com.google.android.gms.** { *; } -keep class com.google.gson.** -keepclassmembers class com.google.gson.** { *; } -keep class com.google.ads.** -keepclassmembers class com.google.ads.** { *; } -keep class bolts.** -keepclassmembers class bolts.** { *; } -keep class com.google.api.client.** { *; } -dontwarn com.google.api.client.* -keep class org.apache.http.** { *; } -dontwarn org.apache.http.* -libraryjars libs #-injars libs/AudienceNetwork.jar #-injars libs/google-api-client-1.18.0-rc.jar #-injars libs/google-api-client-android-1.18.0-rc.jar #-injars libs/google-http-client-android-1.18.0-rc.jar # The official support library. -keep class android.support.v4.** { *; } -keepclassmembers class android.support.v4.** { *; } -keep interface android.support.v4.** { *; } -keep class android.support.v7.** { *; } -keepclassmembers class android.support.v7.** { *; } -keep interface android.support.v7.** { *; } # Library JARs. -keep class com.facebook.** { *; } -keepclassmembers class com.facebook.** { *; } 
+5
source share
2 answers

Add the following lines to proguard-rules.pro

 -keep class android.support.v4.** { *; } -dontnote android.support.v4.** 
+2
source

Replacement

 compile files('libs/google-api-client-1.18.0-rc.jar') compile files('libs/google-api-client-android-1.18.0-rc.jar') compile files('libs/google-http-client-android-1.18.0-rc.jar') 

with

 compile 'com.google.api-client:google-api-client:1.18.0-rc' compile 'com.google.http-client:google-http-client-gson:1.18.0-rc' compile 'com.google.api-client:google-api-client-android:1.18.0-rc' 

fixed problem.

0
source

Source: https://habr.com/ru/post/1236562/


All Articles