Linked Questions

Popular Questions

Xamarin.Forms problems with Embedded Resources and Proguard

Asked by At

I have two different applications, both using files that I've included in my Xamarin.Forms project's root. The files are set as Embedded Resources under "Build Action" and then fetched using the code below.

var assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("test.text.json");

This approach works just fine with all compilation options such as AoT and LLVM, except for when Proguard is involved. If the application is compiled using Proguard it will just instantly force close without being able to read the files.

So far I've tried making exceptions for the classes in the project using a custom proguard.cfg-file that is set as my "ProguardConfiguration" in VS 2017.

-keep class com.companyname.test** { *; }
-keeppackagenames com.companyname.test**

This has not yielded any results. The application still crashes instantly. Every other application using Proguard is working just fine as long as it's not loading any files locally. Should I use a different way of loading files or can I exclude anything else in my Proguard configuration to make this work?

EDIT: Just updating this post to draw attention to the solution. It turns out I have solved this problem before but for some reason it seems to be back. Here is the log output:

android.view.InflateException: Binary XML file line #20: Binary XML file 
line #20: Error inflating class

Which is something that I have already added to my general Proguard rules without me having to add a special Proguard configuration to my project. As a solution this time I simply added these two lines to my proguard.cfg file:

-keep public class** { *; }

Thanks Alen.Toma for pointing me in the right direction.

Related Questions