Skip to content

proguard rules embedded in binding projects are lost #4449

Closed

Description

@softlion

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

  1. Create a demo xamarin android project
  2. Add the OneSignal nuget, and follow the onesignal guides to configure it properly
  3. Build in release mode, using d8, r8 and "link all" options

Expected Behavior

The app should run fine on a device.
These proguard rules (still used by R8) should have been automatically imported by the nuget:
https://github.com/OneSignal/OneSignal-Android-SDK/blob/master/OneSignalSDK/onesignal/consumer-proguard-rules.pro

Actual Behavior

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.

Version Information

Microsoft Visual Studio Enterprise 2019.txt

Activity

  1. added
    Area: App+Library Build
    on Mar 24, 2020
  2. brendanzagaeski commented on Mar 25, 2020

    @brendanzagaeski
    Contributor

    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:

    • library_project_imports/proguard.txt
    • library_project_imports/bin/proguard.txt

    These files match the content of the consumer-proguard-rules.pro file from the OneSignal repository.

    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:

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <ProguardConfiguration Include="$(MSBuildThisFileDirectory)..\..\proguard\monoandroid90\proguard.txt" />
      </ItemGroup>
    </Project>
  3. softlion commented on Mar 25, 2020

    @softlion
    Author

    ty @brendanzagaeski you get the point !

  4. jonathanpeppers commented on Mar 25, 2020

    @jonathanpeppers
    Member

    Yes, I think this is duplicate of: #3752

    We just haven't gotten around to doing this quite yet.

  5. PatGet commented on Sep 29, 2020

    @PatGet

    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?

  6. jonathanpeppers commented on Sep 29, 2020

    @jonathanpeppers
    Member
  7. PatGet commented on Sep 29, 2020

    @PatGet

    I made a mistake and named it target instead of targets. Now it works! Thanks @jonathanpeppers!

  8. jpobst commented on Sep 13, 2022

    @jpobst
    Contributor

    Looks like this was fixed in #5310.

  9. ghost locked as resolved and limited conversation to collaborators on Oct 13, 2022
  10. added
    enhancement
    on Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library Buildenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions