I'm not using jackson in my project. I'm only using gson library and still when I'm trying to build release apk, proguard shows lots of warnings.
Here are the warnings:-
Warning:org.immutables.gson.adapter.ExpectedSubtypesAdapter$JsonParserReaderSupplier: can't find referenced class com.fasterxml.jackson.databind.util.TokenBuffer
Warning:org.immutables.gson.adapter.FieldNamingTranslator: can't find referenced class sun.reflect.ReflectionFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Immutable
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Style
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Style$ImplementationVisibility
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Immutable
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Style
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$GsonProviderOptions: can't find referenced class org.immutables.value.Value$Style$ImplementationVisibility
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonGenerator
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonParser$Feature
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonGenerator$Feature
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonGenerator
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonParser$Feature
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonGenerator$Feature
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonFactory
Warning:org.immutables.gson.stream.GsonMessageBodyProvider$JacksonStreamer: can't find referenced class com.fasterxml.jackson.core.JsonGenerator
Warning:org.immutables.gson.stream.JsonGeneratorWriter: can't find referenced class com.fasterxml.jackson.core.JsonGenerator
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.databind.util.TokenBuffer
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.databind.util.TokenBuffer
Warning:org.immutables.gson.stream.JsonParserReader: can't find referenced class com.fasterxml.jackson.core.JsonParser
Warning:org.immutables.gson.stream.JsonParserReader$2: can't find referenced class com.fasterxml.jackson.core.JsonToken
Warning:org.parceler.ParcelAnnotationProcessor: can't find referenced method 'void init(javax.annotation.processing.ProcessingEnvironment)' in program class org.parceler.transfuse.AnnotationProcessorBase
Warning:org.parceler.ParcelAnnotationProcessor: can't find referenced class com.google.auto.service.AutoService
Warning:org.parceler.apache.commons.beanutils.MappedPropertyDescriptor: can't find referenced method 'void setName(java.lang.String)' in program class org.parceler.apache.commons.beanutils.MappedPropertyDescriptor
Warning:org.parceler.apache.commons.logging.impl.AvalonLogger: can't find referenced class org.parceler.apache.avalon.framework.logger.Logger
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Category
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Priority
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Logger
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Category
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Logger
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Priority
Warning:org.parceler.apache.commons.logging.impl.Log4JLogger: can't find referenced class org.parceler.apache.log4j.Logger
Warning:org.parceler.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.parceler.apache.log.Hierarchy
Warning:org.parceler.apache.commons.logging.impl.LogKitLogger: can't find referenced class org.parceler.apache.log.Logger
Warning:org.parceler.codemodel.util.SingleByteEncoder: can't find referenced class sun.nio.cs.Surrogate$Parser
Warning:org.parceler.codemodel.util.SingleByteEncoder: can't find referenced class sun.nio.cs.Surrogate
Warning:org.parceler.codemodel.util.SingleByteEncoder: can't find referenced class sun.nio.cs.Surrogate$Parser
Warning:org.parceler.codemodel.util.SingleByteEncoder: can't find referenced class sun.nio.cs.Surrogate
Warning:org.parceler.codemodel.util.SingleByteEncoder: can't find referenced class sun.nio.cs.Surrogate$Parser
Warning:org.parceler.guava.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning:org.parceler.guava.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
Warning:org.parceler.guava.cache.Striped64$Cell: can't find referenced class sun.misc.Unsafe
Warning:org.parceler.guava.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator: can't find referenced class sun.misc.Unsafe
Warning:org.parceler.guava.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator$1: can't find referenced class sun.misc.Unsafe
Warning:org.parceler.transfuse.bootstrap.BootstrapProcessor: can't find referenced field 'javax.annotation.processing.ProcessingEnvironment processingEnv' in program class org.parceler.transfuse.bootstrap.BootstrapProcessor
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.JavaFileManager$Location
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.JavaFileManager
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.StandardLocation
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.FileObject
Warning:org.parceler.transfuse.gen.FilerSourceCodeWriter: can't find referenced class javax.tools.JavaFileObject
Warning:org.parceler.transfuse.util.MessagerLogger: can't find referenced class javax.tools.Diagnostic$Kind
Warning:org.parceler.transfuse.util.MessagerLogger: can't find referenced class javax.tools.Diagnostic
Warning:org.parceler.transfuse.util.MessagerLogger: can't find referenced class javax.tools.Diagnostic$Kind
Warning:org.parceler.transfuse.validation.Validator: can't find referenced class javax.tools.Diagnostic$Kind
Warning:org.parceler.transfuse.validation.Validator: can't find referenced class javax.tools.Diagnostic
Warning:org.parceler.transfuse.validation.Validator: can't find referenced class javax.tools.Diagnostic$Kind
Warning:org.parceler.transfuse.validation.Validator$ValidationBuilder: can't find referenced class javax.tools.Diagnostic$Kind
Warning:org.parceler.transfuse.validation.Validator$ValidationBuilder: can't find referenced class javax.tools.Diagnostic
Warning:org.parceler.transfuse.validation.Validator$ValidationBuilder: can't find referenced class javax.tools.Diagnostic$Kind
here is my complete proguard file
# Apache
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.net.**
# ButterKnife 7
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
# Crashlytics 1.+
-keep class com.crashlytics.** { *; }
-keepattributes SourceFile,LineNumberTable
# Deeplink dispatch
-keep class com.airbnb.deeplinkdispatch.** { *; }
-keepclasseswithmembers class * { #com.airbnb.deeplinkdispatch.DeepLink <methods>;}
# Configuration for Fabric Twitter Kit
# See: https://dev.twitter.com/twitter-kit/android/integrate
-dontwarn com.squareup.okhttp.**
-dontwarn com.google.appengine.api.urlfetch.**
-dontwarn rx.**
-dontwarn retrofit.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
#retrofit.http.* *;
}
# Facebook 3.2
-keep class com.facebook.** { *; }
-keepattributes Signature
## Google Play Services 4.3.23 specific rules ##
## https://developer.android.com/google/play-services/setup.html#Proguard ##
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
## GSON 2.2.4 specific rules ##
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON #Expose annotation
-keepattributes *Annotation*
-keepattributes EnclosingMethod
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
# MoPub Proguard Config
# NOTE: You should also include the Android Proguard config found with the build tools:
# $ANDROID_HOME/tools/proguard/proguard-android.txt
# Keep public classes and methods.
-keepclassmembers class com.mopub.** { public *; }
-keep public class com.mopub.**
-keep public class android.webkit.JavascriptInterface {}
# Explicitly keep any custom event classes in any package.
-keep class * extends com.mopub.mobileads.CustomEventBanner {}
-keep class * extends com.mopub.mobileads.CustomEventInterstitial {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}
-keep class * extends com.mopub.mobileads.GooglePlayServicesBanner {}
-keep class * extends com.mopub.nativeads.AvocarrotNativeMopub {}
# Support for Android Advertiser ID.
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}
# Simple-fb
-keep class com.sromku.simple.fb.entities.** { *; }
# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
## Square Otto specific rules ##
## https://square.github.io/otto/ ##
# Otto
-keepattributes *Annotation*
-keepclassmembers class ** {
#com.squareup.otto.Subscribe public *;
#com.squareup.otto.Produce public *;
}
## Square Picasso specific rules ##
## https://square.github.io/picasso/ ##
-dontwarn com.squareup.okhttp.**
# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**
-keepclasseswithmembers class * {
#retrofit.http.* <methods>;
}
# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions
# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
# Also you must note that if you are using GSON for conversion from JSON to POJO representation, you must ignore those POJO classes from being obfuscated.
# Here include the POJO's that have you have created for mapping JSON response to POJO for example.
-keep class com.myproject.model.** { *; }
# Android design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
# app specific
-keepclassmembers class com.myproject.** {
public *;
}
# Removing logs
-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
# Keep the support library
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
## ---------------- End Project specifics ---------------- ##
Please help, how do fix it.
If you are still getting error after adding keepattributes line as suggested by Emanuel Seidinger, please add dontwarn directive for packages causing issues.
-dontwarn org.codehaus.jackson.**
I would attack the problem with a different angle. What I see here is that warnings you provided might indicate unintended leakage of compilation-only artifacts to the actual compile/runtime classpath which is processed by ProGuard.
In particular, annotation processors (such as ParcelAnnotationProcessor) and optional annotations should not be included in the regular compilation scope.
Usually what you can do is to set scope of such dependencies to provided or compileOnly depending on the apt plugin you use (assuming you use Gradle to build android app)
As one of the authors of org.immutables libraries I already faced and discussed some difficulties with a ProGuard which might do not recognize special compile-only scopes etc. In your particular case you use org.immutables:gson artifact which contains optional Jackson-Gson integration bridge classes which are propagated to build. You usually do not need those classes on Android. As a solution I would suggest to just replace org.immutables:gson artifact with annotation-only version available using annotations classifier (using like provided "org.immutables:gson:2.1.11:annotations"). This artifact excludes any unwanted Jackson-dependent classes.
See sample Gradle configuration when using Immutables annotation processor: http://immutables.github.io/getstarted.html#android
I'm also using GSON in an Android project. You can try the proguard configuration found here android-proguard-example. You have to adapt the last line in the example for the model classes in your project which will be serialized using GSON.
I do have the following lines in my proguard config because of GSON:
-keepattributes Signature
-keepattributes *Annotation*
Related
Already implemented below given solution but none of them are working still facing below listed warning.
Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Add these lines into your proguard-rules.pro:
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**
EDIT: try to add this:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
into release buildType.
Adding below lines to the proguard will ignore these warnings solution from here
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-dontwarn javax.annotation.**
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
when I am setting minifiyEnabled to true in my any variant (debug or release) it gives me below error -
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:library class android.webkit.WebView depends on program class android.net.http.SslCertificate
Warning:library class android.webkit.WebViewClient depends on program class android.net.http.SslError
Warning:library class org.apache.http.conn.ssl.SSLSocketFactory depends on program class org.apache.http.conn.scheme.HostNameResolver
Warning:library class org.apache.http.conn.ssl.SSLSocketFactory depends on program class org.apache.http.params.HttpParams
Warning:library class org.apache.http.params.HttpConnectionParams depends on program class org.apache.http.params.HttpParams
Warning:there were 176 unresolved references to classes or interfaces.
Warning:there were 23 instances of library classes depending on program classes.
Warning:there were 6 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForProductionDebug'.
> Job failed, see logs for details
It is working fine in emulator or device if its lolipop or higher.
My problem resolved if i disable or make minifyEnabled to false, but I don't really want so.
My gradle tool is build:gradle:2.3.0'
And multiDexEnabled true
Note - I am not keeping any class or attribute in my proguard-rules.pro file.
After a lot of recherches and experiments I have got the solution. We have to add keep and dontwarn statments in our proguard-rules.pro file -
# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**
-keepclasseswithmembers class * {
#retrofit.http.* <methods>;
}
# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions
# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
# Proguard configuration for amazon Jackson 2.x (fasterxml package instead of codehaus package)
-keep class com.amazonaws.** { *; }
-keepnames class com.amazonaws.** { *; }
-dontwarn com.amazonaws.**
-dontwarn com.fasterxml.**
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-dontwarn org.mockito.**
-dontwarn sun.reflect.**
-dontwarn android.test.**
-dontwarn org.hamcrest.**
-dontwarn android.test.**
-dontwarn android.support.test.**
-keep class org.hamcrest.** {
*;
}
-keep class org.junit.** { *; }
-dontwarn org.junit.**
-keep class junit.** { *; }
-dontwarn junit.**
-keep class sun.misc.** { *; }
-dontwarn sun.misc.**
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient
-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
Note - I followed the warnings in messages and by picking one by one put my proguard rule accordingly.
if you are define proper proguard rules and still issue then please minifyEnabled true use only for application level for other module use minifyEnabled false.
Also if any lintError found and its not possible to solve then use below code
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
I have checked that and its works after so much effort.
Try to add the following lines to your proguard configuration:
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-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
It's for retrofit library. For other external libs you can use this method with own packages which you want to ignore;
-dontwarn org.apache.** - for example
More about ProGuard usage you can find here
I am trying to generate a signed APK with minifyEnabled set to true in Gradle:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
and added these to my proguard file:
-dontwarn okio.**
-dontwarn retrofit.**
but I get these errors:
Information:Gradle tasks [:app:assembleRelease]
Warning:retrofit2.Platform$Java8: can't find referenced method 'boolean isDefault()' in library class java.lang.reflect.Method
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:there were 8 unresolved references to classes or interfaces.
Warning:there were 1 unresolved references to library class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED
and can't build the apk file. We can't have minifyEnabled as true and use retrofit library? how can this be fixed?
You can have minifyEnabled as true and use any number of libraries. Just one thing to make note of its to add the proguard rules of every library in the proguard-rules.pro file. Check retrofits proguard handling here.
Lastly adding a proguard-rules.pro for your reference this is for the project im handling. (You might also need to notify proguard to exclude your POJO classes. Check example)
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/yogeshmalpani/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
-dontwarn com.squareup.okhttp.**
-keep class com.pushwoosh.** { *; }
-keep class com.arellomobile.** { *; }
-dontwarn com.pushwoosh.**
-dontwarn com.arellomobile.**
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { #butterknife.InjectView *;}
-keepattributes *Annotation*,EnclosingMethod,Signature,SourceFile,LineNumberTable
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep class org.codehaus.** { *; }
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
# My POJO class directory
-keep public class com.app_name.model.pojo.** {
public void set*(***);
public *** get*();
public protected private *;
}
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
I think you are using retrofit 2,
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
This question already have been asked many times but I am not able to resolve it. I am trying to export my app using eclipse for final release BUT I am getting the below error. I added all entries which others have suggested in other links but no help. Please help me how to get rid of this error.
Proguard returned with error code 1. See console
[2014-08-24 11:21:11 - ] Note: there were 1035 duplicate class definitions.
[2014-08-24 11:21:11 - ] Warning:com.google.api.client.extensions.jdo.JdoDataStoreFactory$JdoValue: can't find superclass or interface javax.jdo.spi.PersistenceCapable
[2014-08-24 11:21:11 - ] Warning: com.google.api.client.extensions.jdo.JdoDataStoreFactory$JdoDataStore: can't find referenced class javax.jdo.PersistenceManagerFactory
[2014-08-24 11:21:11 -
[2014-08-24 11:21:11 - ] Warning: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential: can't find referenced class com.google.android.gms.common.AccountPicker
[2014-08-24 11:21:11 - ] Warning: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential: can't find referenced class com.google.android.gms.auth.GoogleAuthUtil
You should check if you need to specify additional program jars.
Warning: there were 127 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Error: Please correct the above warnings first.
There was long error so I pasted relevant one. Below is my proguard-project.txt file entries.
-keep class android.support.v4.** { *; }
-dontwarn android.support.v4.**
-dontwarn javax.activation.**
-dontwarn javax.security.**
-dontwarn java.awt.**
-libraryjars <java.home>/lib/rt.jar
-keep class javax.** {*;}
-keep class com.sun.** {*;}
-keep class myjava.** {*;}
-keep class org.apache.harmony.** {*;}
-keep public class Mail {*;}
-dontshrink
-dontwarn org.mockito.**
-dontwarn sun.reflect.**
-dontwarn android.test.**
-keep class javax.ws.rs.** { *; }
-dontwarn com.fasterxml.jackson.**
-dontwarn org.xmlpull.v1.**
I resolved the issue. I added below two lines and now it is not giving any warning and I am able to generate .apk file successfully using eclipse.
-dontwarn javax.jdo.**
-dontwarn com.google.api.client.googleapis.extensions.android.gms.**
Hope it will help someone. Thanks
I'm trying to configure proguard and have faced with some problems which are sorted by priority:
I have received warnings of duplicates zip and cannot fix it.
I use external libraries in "libs" directory and 2 library projects(one library project has one external lib - added to project only once) which are added to project only once. I tried to move my external jars to another directory, i.e. "lib" - just rename due to some users have been managed to solve it so but it doesn't help me. Another way was trying to implement custom_rules to basic build.xml due to it helps some users to avoid these warning. But everything from it doesn't help me, how can I fix it? Log:
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-annotations-2.1.4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [google-analytics-v2.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-core-2.1.4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [httpclientandroidlib-1.1.2.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [deviceprint-lib-1.0.0.jar:META-INF/MANIFEST.MF])
Last thing is some notes during signed apk building:
ProGuard: Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
ProGuard: Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
ProGuard: Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Full proguard file:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# Otherwise return Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.jackson.databind.**
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
# Preserve all fundamental application classes.
-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.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
# Preserve ActionBarSherlock and Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
# Preserve all Jackson library classes
-keep class com.fasterxml.jackson.** { *; }
# Original
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
The 6 warnings and 3 notes that you currently list are harmless.
You should make sure that you are using a recent version of the Android SDK, which creates an empty proguard-project.txt for your project. The standard Ant build and Eclipse build take care of the important configuration internally (I presume you're using Ant from IDEA). You can still add application-specific options to proguard-project.txt, like the -keep options for Jackson and ActionBarSherlock. Do not add options like -injars/-libraryjars/-outjars, since the build process specifies them for you.
There are similar problems discussed here in Stackoverflow:
Android Proguard Duplicate Definition
Duplicate resources when using ProGuard and an Android application
Android - Proguard duplicate zip entry error
In Your case, I think the first one could help You...
If this does not help, we should look from where this issue comes. I even have some apps at playstore with third party libs and I had no problems with proguard. Here are my proguard.cfg settings from one of my app with a third party lib and google lvl licensing:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn **CompatHoneycomb
-keep class android.support.v4.** { *; }
-dontwarn org.apache.**
-verbose
-dontoptimize
-dontshrink
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-dontwarn com.google.ads.**
well, You don´t need all them, it depends what you have implemented or which third party libs You use. So, I couldn´t see your app structure and got no code, this would exceed the scope. I suggest that You just test one by one.