5

I'm trying to use proguard with Xamarin. So I enabled it in project options (checked Enable ProGuard), and I created a file proguard.cfg in Properties, (as new Text file, is it right?) and checked the BuildAction -> ProguardConfiguration

Proguard file config

The proguard file contains only a -keep configuration, with a comment. Whether I leave or remove the comment, I always get a parse error on line 1 :

# test comment 
-keep class !android.support.v7.view.menu.**, !android.support.design.internal.NavigationMenu, !android.support.design.internal.NavigationMenuPresenter, !android.support.design.internal.NavigationSubMenu, android.support.** {*;}

I get a Unknown option '' in line 1 error.

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 1. Output: proguard.ParseException: Unknown option '' in line 1 of file 'Properties/proguard.cfg'
included from argument number 10 at proguard.ConfigurationParser.parse(ConfigurationParser.java:191) at proguard.ProGuard.main(ProGuard.java:484) (WheezMe.Droid)

Any idea ?

Eino Gourdin
  • 4,169
  • 3
  • 39
  • 67

2 Answers2

19

I added this section of the docs awhile back to mention that you need to remove the BOM(Byte order mark):

Note: If you get an error like the following, then your configuration file contains a byte order mark (BOM), which the ProGuard tool cannot handle:

Unknown option '-keep' in line 1 of file 'proguard.cfg'

To prevent this problem, save your custom configuration file from a text editor that allows you to omit the BOM. For example, if you are saving from Notepad++, you can use the Encoding > Encode in UTF-8 Without BOM option to save your ProGuard configuration file without BOM.

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#ProGuard

By all means you can use whatever method you'd like to remove the BOM. Notepad++ makes it pretty simple. Adding the full solution here to help others for visibility.

EDIT:

The proper link can be found here:

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/proguard/#File_Issues

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51
  • Thanks! Notepad++ using "Encode in UTF-8 (without BOM)" works well! – Marco Rinaldi Oct 31 '17 at 09:41
  • 1
    It'd be nice if this process was more refined. When enabling proguard in project settings, it should automatically create a proguard.cfg in the root of the project in UTF-8 encoding. The proguard.cfg file should include some standard commands for keeping google play services classes, etc... That way it doesn't take each developer 4-8 hours to get proguard set up properly. – Justin Jan 19 '18 at 16:48
  • Although the UTF-8 thing is a Visual Studio issue (Which we are working on a fix specifically for Xamarin), the Proguard default keep items actually do pull down Google Play Services and Android Support `proguard.keep` files and includes it in the `Proguard` task. – Jon Douglas Jan 19 '18 at 16:58
5

The byte order mark can also be removed from the file with the following perl command :

perl -e 's/\xef\xbb\xbf//;' -pi~ proguard.cfg 
Eino Gourdin
  • 4,169
  • 3
  • 39
  • 67