ProGuard can't find referenced class android.net.http.AndroidHttpClient - android

When I export a signed apk, the following error is shown:
Proguard returned with error code 1. See console
Warning: com.google.android.gms.internal.zzaj: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzak
Warning: com.google.android.gms.internal.zzak: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzak
Warning: com.google.android.gms.internal.zzar: can't find referenced class android.net.http.AndroidHttpClient
Is it safe to just add these Proguard rules:
-keep class android.net.http.AndroidHttpClient
-dontwarn android.net.http.AndroidHttpClient
Or do I also have to include org.apache.http.legacy.jar in the project?

Add this line to your proguard. It will not affect anything in your code
-dontwarn org.apache.http.**

Related

Android proguard crashed when Azure mobile app is used

I use Azure mobile app in my new Android project.
When I run the app on debug mode, the Mobile app works successfully and I can see my new records in my table.
My problem is starting when I creates an apk file with proguard.
I am sorry to say that I am newbie on Proguard then I can not solve my Proguard problems even I read the documentation at offical Proguard page.
So, I get these errors when I try to create apk file with Proguard without any Proguard code.
Warning: com.google.common.base.Absent: can't find referenced class javax.annotation.Nullable
Warning: com.google.common.base.Absent: can't find referenced class javax.annotation.Nullable
Warning: com.google.common.base.Ascii: can't find referenced class javax.annotation.CheckReturnValue
Warning: com.google.common.base.CaseFormat$StringConverter: can't find referenced class javax.annotation.Nullable
Warning: com.google.common.base.CharMatcher: can't find referenced class javax.annotation.CheckReturnValue
Warning: com.google.common.base.CharMatcher: can't find referenced class javax.annotation.CheckReturnValue
Warning: com.google.common.base.CharMatcher: can't find referenced class javax.annotation.CheckReturnValue
and more hundreads line...
Warning: com.google.common.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
Warning: com.google.common.cache.Striped64$1: can't find referenced class sun.misc.Unsafe
and more hundreads line....
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Then I added these line in my proguard.
-keep class okio.** { *; }
-dontwarn okio.**
-keep class com.fasterxml.** { *; }
-dontwarn com.fasterxml.**
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe
-keep class com.microsoft.windowsazure.mobileservices.** { *; }
-dontwarn android.os.**
-dontwarn com.microsoft.windowsazure.mobileservices.RequestAsyncTask
After that, Android studio created the apk however The app crahsed as soon as It started. Then I investigate the logs, I saw new warnings that color are white.
Note: duplicate definition of library class [org.apache.http.conn.scheme.LayeredSocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver]
Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException]
Note: duplicate definition of library class [org.apache.http.params.CoreConnectionPNames]
Note: duplicate definition of library class [org.apache.http.params.HttpParams]
Note: duplicate definition of library class [org.apache.http.params.HttpConnectionParams]
Note: duplicate definition of library class [android.net.http.SslError]
Note: duplicate definition of library class [android.net.http.HttpResponseCache]
Note: duplicate definition of library class [android.net.http.SslCertificate$DName]
Note: duplicate definition of library class [android.net.http.SslCertificate]
Note: there were 11 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Thanks for help.
#MustafaOlkun, It seems that the solutions for your issues can be found at the troubleshooting page of ProGuard.
For the issue Warning: can't find referenced class, please see http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass.
For the issue Note: duplicate definition of library class, please see http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass.
Hope it helps.

samsung multiscreen Proguard conflict with exoplayer

I want to release my app but in proguard step I face a problem. it Generate some warning when I add lobmok ( or be more specific when I add samsung-multiscreen jar file) as follows :
Warning:com.google.android.exoplayer.MediaCodecAudioTrackRenderer:
can't find referenced class android.media.PlaybackParams
Warning:com.google.android.exoplayer.audio.AudioTrack: can't find
referenced class android.media.PlaybackParams
Warning:com.google.android.exoplayer.audio.AudioTrack$AudioTrackUtil:
can't find referenced class android.media.PlaybackParams
Warning:com.google.android.exoplayer.audio.AudioTrack$AudioTrackUtilV23:
can't find referenced class android.media.PlaybackParams
Warning:com.google.android.exoplayer.audio.AudioTrack$AudioTrackUtilV23:
can't find referenced method 'void
setPlaybackParams(android.media.PlaybackParams)' in library class
android.media.AudioTrack
Warning:com.google.android.exoplayer.audio.AudioTrack$AudioTrackUtilV23:
can't find referenced class android.media.PlaybackParams
Warning:com.google.android.exoplayer.chunk.VideoFormatSelectorUtil:
can't find referenced method 'android.view.Display$Mode getMode()' in
library class android.view.Display
Warning:com.google.android.exoplayer.chunk.VideoFormatSelectorUtil:
can't find referenced class android.view.Display$Mode
When I add following line to proguard-rules.pro some of the them disappeared but When I launch to the application it crash.
-dontwarn lombok.**
Also try this :
-keep class com.google.android.exoplayer.** { *; }
I think it raise due to conflict between annotation used in exoplayer and multiscreen (lombok)
does anyone knows how to fix this issue ?
Finally I fixed this issue with following proguard-rule:
-ignorewarnings
-dontoptimize
-dontobfuscate
-dontskipnonpubliclibraryclasses
-ignorewarnings
-keep class com.samsung.** { *; }
-dontwarn com.samsung.**
-dontwarn com.samsung.multiscreen.BuildConfig
-dontwarn lombok.**

Is there an valid proguard rule for RxJava and FasterXML?

Now the only problem stopping me from using kotlin in production is that I can't find a correct proguard file for it.
What I used:
1.Kotlin
2.Anko
3.Jackson-Kotlin-module
Here's the warning message:
:app:proguardRelease
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.ConcurrentCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.ConcurrentSequencedCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.MpscLinkedQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.SpscArrayQueue: can't find referenced class sun.misc.Unsafe
Warning: rx.internal.util.unsafe.UnsafeAccess: can't find referenced class sun.misc.Unsafe
Warning: there were 41 unresolved references to classes or interfaces.
It has nothing to do with Kotlin. Ignore the warnings in your proguard file:
-dontwarn sun.misc.Unsafe
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
a better is just to have this aar as a dependency:
https://github.com/artem-zinnatullin/RxJavaProGuardRules

Android signed APK generation : Proguard exception for referenced class / method not found

I need to generate a signed APK for Play Store. ( using Android Studio )
If I do that without proguard ( minifyEnabled false in build.gradle ) all works fine!
If I activate it with default parameters :
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I receive these warnings
:app:proguardRelease
Warning: com.android.volley.error.VolleyErrorHelper$1: can't find superclass or interface com.google.gson.reflect.TypeToken
Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced method 'java.lang.reflect.Type getType()' in program class com.android.volley.error.VolleyErrorHelper$1
Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken
Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken
Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson
Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException
Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: there were 28 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 3 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:473)
at proguard.ProGuard.initialize(ProGuard.java:233)
at proguard.ProGuard.execute(ProGuard.java:98)
at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:137)
at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:113)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
at java.lang.Thread.run(Thread.java:745)
:app:dexRelease UP-TO-DATE
:app:validateExternalOverrideSigning
:app:packageRelease
And the build process stop with this message :
Error:Execution failed for task ':app:packageRelease'.
> Unable to compute hash of ...\app\build\intermediates\classes-proguard\release\classes.jar
After several tentatives I've found a way to remove the warnings with this lines in my "proguard-rules.pro" :
-dontwarn com.android.volley.**
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
But the build process still goes in error!
Anyone have a workaround for this problem?
Thanks!
Davide
After several attemps ... here the solution :
First configure the dontwarn as suggested by Raymond ( maybe this is not necessary but i left it ) :
-dontwarn com.google.gson.**
-dontwarn java.nio.file.**
-dontwarn org.codehaus.mojo.animal_sniffer.**
-dontwarn com.squareup.okhttp.internal.huc.**
-dontwarn com.android.volley.error.**
Then configure Proguard to skip my library :
-keep class com.android.volley.error.** { *; }
-keep class com.squareup.okhttp.internal.huc.** { *; }
-keep class okio.** { *; }
Ather that the compilation was ok but on runtime the application crashed.
So, to avoid this problem, i've added these lines :
-keep class android.support.design.widget.** { *; }
-keep interface android.support.design.widget.** { *; }
-dontwarn android.support.design.**
based on some info found from this thread :
java.lang.RuntimeException: Could not inflate Behavior subclass
With this settings i'm able to generate a signed APK of my app.
You have to apply dontwarn to the referenced class instead.
For example:
-dontwarn com.google.gson.**
-dontwarn java.nio.file.**

gradle - proguard errors do not reflect -dontwarn

gradle 1.10 on linux on CLI
./gradlew clean
./gradlew assembleRelease
ERROR in stdout...
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 5 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)
Warning: there were 106 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
:proguardRelease FAILED
:proguardRelease (Thread[main,5,main]) completed. Took 4.689 secs.
FAILURE: Build failed with an exception.
I extend an oss package bundled with gradle for release builds ( added jackson.json but not from maven central ).
For some reason, proguard is throwing hundreds of 'org.joda.time... class not found' errors despite the following snips:
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
} // in 'build.gradle'
-dontwarn android.support.**
-dontwarn org.joda.time.**
-dontwarn org.codehaus.jackson.**
-dontwarn ch.boye.httpclientandroidlib.**
-dontwarn org.apache.http.**
-dontwarn android.**
-dontwarn java.**
-dontwarn com.google.sample.castcompanionlibrary.**
-dontwarn org.w3c.dom.**
-dontwarn com.google.android.gms.maps.**
#rcr adds
-libraryjars /usr/local/src/android-sdk-linux/platforms/android-19/android.jar
-libraryjars <java.home>/lib/rt.jar
-libraryjars libs/jackson-core-lgpl-1.9.2.jar
-libraryjars libs/jackson-mapper-lgpl-1.9.2.jar
-libraryjars libs/Parse-1.1.3.jar
-libraryjars libs/httpclient-1.1.jar
stdout DETAIL from './gradlew assembleRelease' below:
Initializing...
Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Note: the configuration refers to the unknown class 'Object'
Maybe you meant the fully qualified name 'java.lang.Object'?
Warning: org.codehaus.jackson.map.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: org.codehaus.jackson.map.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: org.codehaus.jackson.map.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: org.codehaus.jackson.map.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: org.codehaus.jackson.map.ext.JodaDeserializers: can't find referenced class org.joda.time.DateTime
Warning: org.codehaus.jackson.map.ext.JodaDeserializers: can't find referenced class org.joda.time.ReadableDateTime
Warning: org.codehaus.jackson.map.ext.JodaDeserializers: can't find referenced class org.joda.time.ReadableInstant
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateMidnight
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateMidnight
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateMidnight
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateTime
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateTime
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateMidnight
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateTime
Warning: org.codehaus.jackson.map.ext.JodaDeserializers$DateMidnightDeserializer: can't find referenced class org.joda.time.DateMidnight
Warn
... 100s more in 'org.joda.time.**'
Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
Note: com.google.android.gms.maps.internal.q: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImplGmm6
Note: com.google.android.gms.maps.internal.q: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImpl
Note: org.codehaus.jackson.map.deser.BasicDeserializerFactory: can't find dynamically referenced class java.util.ConcurrentNavigableMap
Note: org.codehaus.jackson.map.deser.BasicDeserializerFactory: can't find dynamically referenced class java.util.ConcurrentSkipListM
The -dontwarn proguard configs for 'org.joda.**' dont seem to work..
I have "-dontnote **ILicensingService" in config and that does not appear to work.
The -dontwarn config for com.google.android.gms.** not working
The -dontwarn for java.util.** not working
In what file is your "snippet" with the -dontwarn flags? It doesn't look like you're ever telling your build.gradle file about that proguard configuration.
You have:
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
But you should also have:
proguardFile 'your_proguard_config.cfg'
so that it will use both the default android configuration and your configuration.

Categories

Resources