You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
proguard rules embedded in binding projects are lost #4449
The proguard rules embedded in binding projects, pulled from nuget, are lost/ignored.
I have seen this behavior for many android binding libraries. It happens since Android have made possible to automatically include proguard rules of referenced android libraries in the final app, about 2 or 3 years ago.
Steps to Reproduce
Create a demo xamarin android project
Add the OneSignal nuget, and follow the onesignal guides to configure it properly
Build in release mode, using d8, r8 and "link all" options
Some java classes from onesignal are missing, and the app is crashing.
Adding the content of the above rules to a local proguard.cfg file does fix the issue.
I think Com.OneSignal is the example NuGet package. The lib/MonoAndroid10/OneSignal.Android.Binding.dll file from that package has an embedded __AndroidLibraryProjects__.zip resource that contains:
Android have made possible to automatically include proguard rules of referenced android libraries in the final app
I'm not familiar with the corresponding Android Studio or Gradle behaviors. Maybe the default Gradle configuration automatically searches for proguard.txt files in referenced libraries and uses them?
As a quick point of comparison, the Xamarin.Android.Support.v7.AppCompat NuGet package takes a different approach where it includes the ProGuard configuration file as a standalone proguard/monoandroid90/proguard.txt file within the NuGet package and then uses build/monoandroid90/Xamarin.Android.Support.v7.AppCompat.targets to add that file to the Xamarin.Android build process:
Should the way @brendanzagaeski mention for Xamarin.Android.Support.v7.AppCompat work in a nuget right now?
Do I need do do anything besides adding the target and txt files to the nuspec?
Activity
brendanzagaeski commentedon Mar 25, 2020
Notes to the Xamarin.Android team
I think Com.OneSignal is the example NuGet package. The lib/MonoAndroid10/OneSignal.Android.Binding.dll file from that package has an embedded __AndroidLibraryProjects__.zip resource that contains:
These files match the content of the consumer-proguard-rules.pro file from the OneSignal repository.
I'm not familiar with the corresponding Android Studio or Gradle behaviors. Maybe the default Gradle configuration automatically searches for proguard.txt files in referenced libraries and uses them?
As a quick point of comparison, the Xamarin.Android.Support.v7.AppCompat NuGet package takes a different approach where it includes the ProGuard configuration file as a standalone proguard/monoandroid90/proguard.txt file within the NuGet package and then uses build/monoandroid90/Xamarin.Android.Support.v7.AppCompat.targets to add that file to the Xamarin.Android build process:
softlion commentedon Mar 25, 2020
ty @brendanzagaeski you get the point !
jonathanpeppers commentedon Mar 25, 2020
Yes, I think this is duplicate of: #3752
We just haven't gotten around to doing this quite yet.
PatGet commentedon Sep 29, 2020
Should the way @brendanzagaeski mention for Xamarin.Android.Support.v7.AppCompat work in a nuget right now?
Do I need do do anything besides adding the target and txt files to the nuspec?
jonathanpeppers commentedon Sep 29, 2020
All you should have to do is put a
.targetsor.propsfile in thebuilddirectory:https://docs.microsoft.com/nuget/create-packages/creating-a-package#from-a-convention-based-working-directory
I do believe the file has to be named the same as the package. So for
My.Package.nupkgit would beMy.Package.targets.Here is a recent example of Xamarin.AndroidX.Migration:
https://github.com/xamarin/AndroidX/blob/34ca438ae886081cee595bf37ac9ac08b5be37f9/source/migration/BuildTasks/Xamarin.AndroidX.Migration.nuspec#L39-L40
PatGet commentedon Sep 29, 2020
I made a mistake and named it target instead of targets. Now it works! Thanks @jonathanpeppers!
jpobst commentedon Sep 13, 2022
Looks like this was fixed in #5310.