Bug 60087 - Proguard fails when you use SDK >23 and Google SDK
Summary: Proguard fails when you use SDK >23 and Google SDK
Status: RESOLVED FIXED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2017-10-10 11:35 UTC by Jonathan ANTOINE
Modified: 2017-12-08 19:17 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro project (4.95 MB, application/x-zip-compressed)
2017-10-25 15:46 UTC, Jonathan ANTOINE
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jonathan ANTOINE 2017-10-10 11:35:08 UTC
When activating Proguard using an Android SDK > and Google Play SDK (Admob for instance) build fails because it does not find org.apache.http classes (logs below). 

You can fix it using Gradles by adding an optional jar (source : https://stackoverflow.com/questions/32773291/proguard-build-fail-unresolved-references) but how can we fix it using Xamarin.



Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateParseException
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.ClientProtocolException
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Comment 1 Jon Douglas [MSFT] 2017-10-23 14:58:27 UTC
This is most likely because Google had deprecated this reference and includes it in an optional folder:

{ANDROID_SDK}\platforms\android-26\optional\org.apache.http.legacy.jar

This has been this way since API 23 which might explain the issues you're having:

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

So the real question is...Are you using a Google Play Services version that is released alongside Android API 23+? In other words, can you please provide all the version information for your packages in this project? If you are on old versions, can you please ensure you are on the latest stable versions?
Comment 2 Sergei 2017-10-25 05:32:57 UTC
I have such error too. I use API 25 and Google Play Services 10.2.1.
Comment 3 Jon Douglas [MSFT] 2017-10-25 15:09:25 UTC
Is there a reproduction project or steps available so I can attach a reproduction project to this bug report? If you already have a reproduction handy, please attach it to this bug report!

Thank you!
Comment 4 Jonathan ANTOINE 2017-10-25 15:45:47 UTC
Here are some repro step :

1° Add the Xamarin.GooglePlayServices.Ads nuget package,
2° Activate Proguard in the app's properties,
3° try to build.

I attach a repro project too :)
Comment 5 Jonathan ANTOINE 2017-10-25 15:46:05 UTC
Created attachment 25450 [details]
Repro project
Comment 6 Jon Douglas [MSFT] 2017-10-25 16:44:02 UTC
This issue is because of the org.apache.http removal since Android 6.0 thus why this only happens on Android 23+:

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

What ends up happening in this case is that because the Google Play Services - Basement.aar has internal classes that still reference these apache http client classes and thus throws Proguard warnings because the classes cannot be found.

To fix this, I believe we need to add an "EmbeddedReferenceJar" to "org.apache.http.legacy.jar" which is found in:

platforms/{android-23+}/optional/org.apache.http.legacy.jar

A current workaround:

You can create a Proguard.cfg file and set the Build Action to "ProguardConfiguration" (Ensure you remove the BOM mark using Notepad++ or similar)

You can then add the following to your custom configuration:

-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.**

This will allow your project to build.
Comment 7 Jonathan ANTOINE 2017-10-25 16:49:44 UTC
You have the correct diagnostic and your work around works well but it would be nearly the same as without Programs as all this Google play services classes would be kept and the package would be nearly as big as without the proguard pass. 

Thanks for working on it! 😊
Comment 8 Jon Douglas [MSFT] 2017-10-25 16:54:33 UTC
(In reply to Jonathan ANTOINE from comment #7)
> You have the correct diagnostic and your work around works well but it would
> be nearly the same as without Programs as all this Google play services
> classes would be kept and the package would be nearly as big as without the
> proguard pass. 
> 
> Thanks for working on it! 😊

By all means it's a way to build your project although it keeps most classes. If you want to be more specific with your proguard definition, please see my blog on this topic which has two links of commonly used proguard configuration items:

https://www.jon-douglas.com/2017/07/20/proguard-notes/
https://www.jon-douglas.com/2016/11/22/xamarin-android-proguard/

You can find the proguard configuration files provided by google inside their aars.

EX: {ANDROID SDK}\extras\google\m2repository\com\google\android\gms\play-services-ads\10.2.1

Extract the .aar and you'll find a "proguard.txt" with more specific rules. I believe we are working on getting this included automatically with NuGet:

https://github.com/xamarin/XamarinComponents/pull/166

In the meantime we will investigate to fix this within our Google Play Services bindings. :)
Comment 9 Jon Dick 2017-10-25 17:03:23 UTC
Feel free to try the 60.1142.0-beta1 nuget packages for play services / firebase, which should contain the proguard.txt files in them.  You may still need this additional proguard.txt fix too, not sure.

We will investigate the warnings due to the apache http stuff missing.
Comment 10 Jon Douglas [MSFT] 2017-10-26 18:12:49 UTC
As an additional update, you can include the following in your Proguard.cfg which should resolve these warnings but may cause harmless duplication notes. This can be an alternative to the -dontwarn rules:

Windows:

-libraryjars C:\Users\{username}\AppData\Local\Android\sdk\platforms\android-26\optional

Mac:

-libraryjars /Users/{username}/Library/Developer/Xamarin/android-sdk-macosx/platforms/android-26/optional/

Please note that the {android-26} item should be the same version that you are compiling against.
Comment 11 Jon Dick 2017-12-08 19:17:44 UTC
This is fixed in 60.1142.0.

The custom build task in Play Services Basement now includes the .jar in proguard if it detects that it exists in the android sdk for the api level you are using:

https://github.com/xamarin/GooglePlayServicesComponents/blob/11.x/basement/buildtasks/Xamarin.GooglePlayServices.Basement.targets#L100-L108