Skip to content

Commit 0a5a5e7

Browse files
author
Mohit
authored
[Common] Update proguard rules, Fixes AB#3340920 (#2756)
Updated proguard rules 1. Keep annotation at AndroidBase64, since it is used by reflection 2. removed com.microsoft.identity* from keeps but keeping names to help with logging and exception. So, names are not obfuscated. 3. Updated build.gradle for jcipAnnotationVersion dependency as it provides runtime objects, to avoid any issues. 4. Added donotwarn for compile time classes (annotations) 5. Major version bump as it can require consumers to adjust their code to avoid build time/runtime issues. Fixes [AB#3340920](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3340920) Run: https://identitydivision.visualstudio.com/Engineering/_build/results?buildId=1532428&view=results
1 parent 6ed9f94 commit 0a5a5e7

4 files changed

Lines changed: 43 additions & 12 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vNext
22
----------
3+
- [MAJOR] Update proguard rules in common (#2756)
34
- [MINOR] Add query parameter for Android Release OS Version (#2754)
45
- [MINOR] Add client scenario to JwtRequestBody (#2755)
56

common/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ dependencies {
174174
implementation "androidx.credentials:credentials-play-services-auth:$rootProject.ext.AndroidCredentialsVersion"
175175
implementation "com.google.android.gms:play-services-fido:$rootProject.ext.LegacyFidoApiVersion"
176176
implementation "com.google.android.libraries.identity.googleid:googleid:$rootProject.ext.GoogleIdVersion"
177+
implementation "com.github.stephenc.jcip:jcip-annotations:$rootProject.ext.jcipAnnotationVersion"
177178

178179
constraints {
179180
implementation ("com.squareup.okio:okio:3.4.0") {

common/consumer-rules.pro

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,33 @@
1717
#}
1818

1919
##---------------Begin: proguard configuration for Common --------
20-
# Intentionally blank, left to consumers of common to implement.
20+
# keep with optmizations and shrinking, but do not obfuscate
21+
-keep,allowoptimization,allowshrinking class !com.microsoft.identity.common.java.nativeauth.**, !com.microsoft.identity.common.nativeauth.**, com.microsoft.identity.** { *; }
22+
-keep class * extends com.microsoft.identity.common.java.authorities.Authority { *; }
23+
-keep class * extends com.microsoft.identity.common.java.authorities.AzureActiveDirectoryAudience { *; }
24+
-keep class * extends com.microsoft.identity.common.java.cache.ICacheRecord { *; }
25+
-keep class * extends com.microsoft.identity.common.java.cache.ITokenCacheItem { *; }
26+
-keep class * extends com.microsoft.identity.common.java.authscheme.AbstractAuthenticationScheme { *; }
27+
-keep class com.microsoft.identity.common.internal.broker.AuthUxJsonPayload { *; }
28+
29+
30+
#For Android Credential Manager: https://developer.android.com/training/sign-in/passkeys#proguard
31+
-if class androidx.credentials.CredentialManager
32+
-keep class androidx.credentials.playservices.** {
33+
*;
34+
}
35+
36+
# Runtime annotations
37+
-keep class net.jcip.annotations.GuardedBy
38+
-keep class net.jcip.annotations.Immutable
39+
-keep class net.jcip.annotations.ThreadSafe
40+
41+
# Compile time annotations
42+
-dontwarn edu.umd.cs.findbugs.annotations.NonNull
43+
-dontwarn edu.umd.cs.findbugs.annotations.Nullable
44+
-dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings
45+
46+
-keepattributes SourceFile,LineNumberTable
2147

2248
##---------------Begin: proguard configuration for Nimbus ----------
2349
# Intentionally blank, left to consumers of common to implement.
@@ -28,7 +54,7 @@
2854
##---------------Begin: proguard configuration for Gson --------
2955
# Gson uses generic type information stored in a class file when working with fields. Proguard
3056
# removes such information by default, so configure it to keep all of it.
31-
-keepattributes Signature
57+
-keepattributes Signature,SourceFile,LineNumberTable
3258

3359
# For using GSON @Expose annotation
3460
-keepattributes *Annotation*
@@ -37,26 +63,27 @@
3763
-dontwarn sun.misc.**
3864
#-keep class com.google.gson.stream.** { *; }
3965

40-
# Application classes that will be serialized/deserialized over Gson
41-
-keep class com.google.gson.examples.android.model.** { <fields>; }
42-
4366
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
4467
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
4568
-keep class * extends com.google.gson.TypeAdapter
4669
-keep class * implements com.google.gson.TypeAdapterFactory
4770
-keep class * implements com.google.gson.JsonSerializer
4871
-keep class * implements com.google.gson.JsonDeserializer
72+
-keep class com.google.gson.reflect.TypeToken { *; }
73+
-keep class * extends com.google.gson.reflect.TypeToken { *; }
4974

75+
##---------------Begin: proguard configuration for OpenTelemetry --------
5076
# keep everything in this package from being removed or renamed
5177
-keep class io.opentelemetry.** { *; }
5278

5379
# Prevent R8 from leaving Data object members always null
54-
-keepclassmembers,allowobfuscation class * {
80+
-keepclassmembers class com.microsoft.identity.** {
5581
@com.google.gson.annotations.SerializedName <fields>;
82+
@com.squareup.moshi.Json <fields>;
5683
}
5784

58-
#For Android Credential Manager: https://developer.android.com/training/sign-in/passkeys#proguard
59-
-if class androidx.credentials.CredentialManager
60-
-keep class androidx.credentials.playservices.** {
61-
*;
62-
}
85+
## Other
86+
# Compile time annotation
87+
-dontwarn com.google.auto.value.AutoValue$CopyAnnotations
88+
-dontwarn com.google.auto.value.AutoValue
89+
-dontwarn com.google.auto.value.extension.memoized.Memoized

common/src/main/java/com/microsoft/identity/common/base64/AndroidBase64.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.base64
2424

25+
import androidx.annotation.Keep
2526
import com.microsoft.identity.common.java.base64.Base64Flags
2627
import com.microsoft.identity.common.java.base64.Base64Util
2728
import com.microsoft.identity.common.java.base64.IBase64
@@ -33,8 +34,9 @@ import com.microsoft.identity.common.java.base64.IBase64
3334
* you'll need to make change in [Base64Util] too.
3435
*
3536
* see [Base64Util] for more info.
37+
* This is called using reflection from [Base64Util], hence the @Keep annotation.
3638
**/
37-
39+
@Keep
3840
class AndroidBase64 : IBase64 {
3941

4042
override fun encode(input: ByteArray, vararg flags: Base64Flags): ByteArray {

0 commit comments

Comments
 (0)