Where do Proguard rules go in a Visual Studio 2015 solution?

I was using Proguard and it was working well with only a few minor warnings about duplicate zip entries for MANIFEST.MF and duplicate .readme resources, which according to the Net I can ignore.

I added "Google Play Services - Ads" packages for ads. Proguard started going nuts with complaints and even resulting in failed compilation ...

2>PROGUARD : warning : com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
2>PROGUARD : warning : com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
2>PROGUARD : warning : com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
2>PROGUARD : warning : com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
2>PROGUARD : warning : com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
2>PROGUARD : warning : com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
...
2>PROGUARD : warning : there were 87 unresolved references to classes or interfaces.
2>PROGUARD : warning : there were 2 unresolved references to program class members.
2>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2015,3): error MSB6006: "java.exe" exited with code 1.

Forum comments suggested that adding ...

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

... to a proguard-project.txt file in the project would fix the issue.

I experimented with a variety of locations (and filenames, including proguard-rules.pro and even adding the rules to the proguard-project.txt file in the android-sdk folder), but the only way I could get Proguard to accept these settings was by adding them directly to the bottom of the proguard-android.txt file at ...

C:\Program Files (x86)\Android\android-sdk\tools\proguard\proguard-android.txt

That's not right AFAICT. Those settings should be provided in a project-specific file within the project.

The good news is that except for a few minor warnings that according to the Net I can ignore ...

2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [formsviewgroup.jar:META-INF/MANIFEST.MF])
2>PROGUARD : warning : can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])
2>PROGUARD : warning : can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

... these settings did work. However, they clearly aren't in the right spot. They should be in a project-based file within the VS solution.

Question: What filename should I be using for project-specific Proguard rules such as those? Where can I place that file in a Xamarin Visual Studio 2015 PCL-based solution to get Proguard to honor the settings?

Answers

  • AquablueAquablue USMember ✭✭

    Hello seattlecreations,

    What filename should I be using for project-specific Proguard rules such as those?

    You can use whatever name you like.
    For instance in our project we have a file called Proguard.cfg.

    Where can I place that file

    You can place it anywhere you want within your Android project structure, but remember to set the Build Action property to ProguardConfiguration.
    Here's an example of what you could do:

    and the corresponding settings:

    Another important point: don't edit the file with Visual Studio as VS will add a byte order mark (BOM) at the beginning of your file and Proguard will not be able to read your configuration file. Edit the configuration file with an editor that let you choose the right file encoding, e.g. UTF-8 without BOM.
    If you have Notepad++ then this is the settings you should use:

    Cheers

  • JustinTemplarJustinTemplar USMember

    Your Proguard settings of:

    -keep class com.google.android.gms.** { *; }
    -dontwarn com.google.android.gms.**

    work great had the same issues with google map services

  • bobsubobsu TWMember

    Thanks, Aquablue
    In VS 2017, I try it follow the steps to fix the same problems.

  • abdalrhmanabdalrhman Member ✭✭

    @Aquablue said:
    Hello seattlecreations,

    What filename should I be using for project-specific Proguard rules such as those?

    You can use whatever name you like.
    For instance in our project we have a file called Proguard.cfg.

    Where can I place that file

    You can place it anywhere you want within your Android project structure, but remember to set the Build Action property to ProguardConfiguration.
    Here's an example of what you could do:

    and the corresponding settings:

    Another important point: don't edit the file with Visual Studio as VS will add a byte order mark (BOM) at the beginning of your file and Proguard will not be able to read your configuration file. Edit the configuration file with an editor that let you choose the right file encoding, e.g. UTF-8 without BOM.
    If you have Notepad++ then this is the settings you should use:

    Cheers

    Thanks For You

Sign In or Register to comment.