microsoft-authentication-library-for-android: Proguard not supported by default

When using proguard + msal, the following rules are required to make the client work:

# This enum is accessed via reflection in common msal lib thus proguard removes it.
-keep public enum com.microsoft.identity.common.internal.ui.AuthorizationAgent  {
    *;
}

# Classes for below package is used by MSAL library. Ignore warning coming from the dependency.
-dontwarn com.nimbusds.jose.**

This rules can be packaged directly in the msal library and common library instead of asking developers to do so.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 15 (9 by maintainers)

Most upvoted comments

I have an issue with Proguard too when using MSAL v1.0.0:

java.lang.AssertionError: AssertionError (GSON 2.8.5): java.lang.NoSuchFieldException: DEFAULT
        at e.d.d.q.a(Gson.java:944)
        at e.d.d.q.a(Gson.java:892)
        at e.d.d.q.a(Gson.java:841)
        at e.d.d.q.a(Gson.java:813)
        at com.microsoft.identity.client.K.a(PublicClientApplicationConfigurationFactory.java:156)
        at com.microsoft.identity.client.K.b(PublicClientApplicationConfigurationFactory.java:110)
        at com.microsoft.identity.client.K.a(PublicClientApplicationConfigurationFactory.java:66)

UPDATE : This issue was fixed when I added the configuration file provided by the link in the previous post and the following lines:

-keep public enum com.microsoft.identity.client.configuration.AccountMode { *; }
-keep public class com.microsoft.identity.client.configuration.HttpConfiguration { *; }
-keep public class com.microsoft.identity.client.configuration.LoggerConfiguration { *; }

This is what came up when fixing the rules when used in AppCenter:

https://github.com/microsoft/AppCenter-SDK-Android/pull/1149/files#diff-54abb45c98c994c8e22a56dc46f07a0b

This covers basic AAD B2C scenarios but you might want to apply that keep rules to every model or enum used via Gson.

We can already do it in proguard, the Microsoft AppCenter SDK uses this already.

Just needs

android {

        defaultConfig {
            consumerProguardFiles 'proguard-rules.pro'

In the build.gradle for the library.

It will be automatically added by android gradle plugin as proguard.txt in the AAR file and added to app rules if consumed as a dependency.