# Keep filenames and line numbers for stack traces
-keepattributes SourceFile,LineNumberTable

# WebView bridge (AndroidWebViewContainer.addJavascriptInterface). WebView resolves
# @JavascriptInterface reflectively, so the annotation must reach the output dex
# (-keepattributes controls what R8 writes, not what it matches on) and the method
# names must survive, since JS calls them by name. AGP's default file happens to
# supply both, but a library cannot assume the consumer applies it. The class name
# is free to be obfuscated -- JS addresses the injected object by its bridge name.
-keepattributes RuntimeVisibleAnnotations
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

# Public API surface. Kept by name rather than left to reachability because the
# Unity Engine C# plugin (AndroidJavaClass / AndroidJavaObject / AndroidJavaProxy)
# and LevelPlay (Class.forName("com.unity3d.ads.UnityAds")) resolve it by string,
# where R8 cannot see the reference. Internals (core.*, adplayer.*, services.core.*,
# banners.bridge, ...) stay shrinkable.
-keep class com.unity3d.ads.* { public *; }
-keep class com.unity3d.ads.metadata.* { public *; }
-keep class com.unity3d.services.banners.* { public *; }
-keep class com.unity3d.services.banners.view.* { public *; }

# MetaData declares three private set(String, <primitive>) overloads that exist only
# for the Unity C# plugin, whose AndroidJavaObject.Call resolves them by exact JNI
# descriptor. Nothing in Java or Kotlin calls them, so `public *` above is not enough
# and R8 deletes them outright -- confirmed in a minified build, where all three
# appeared in R8's usage.txt. Losing them breaks Advertisement.SetMetaData for bool,
# int and long values (consent flags, player age) in release builds only.
-keepclassmembers class com.unity3d.ads.metadata.MetaData {
    private boolean set(java.lang.String, boolean);
    private boolean set(java.lang.String, int);
    private boolean set(java.lang.String, long);
}

# protobuf-javalite ships no consumer rules of its own and resolves message fields by
# name from the RawMessageInfo strings baked into each message. This must cover every
# generated message wherever it lands (gatewayprotocol.v1, com.unity3d.ads.datastore,
# ...) or init dies with "Field <name>_ for <class> not found". Keeping only the
# fields still lets R8 shrink messages that are never referenced.
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
    <fields>;
}

# The rest of upstream's lite config (protobuf/java/lite/proguard.pgcfg), in place of
# keeping the whole runtime -- nothing resolves com.google.protobuf.* by name, and the
# runtime lands in the consuming app, where a package-wide keep froze it for every
# library that uses it. DoNotInline and assumeLiteRuntime do not exist in the 3.25.x
# runtime the SDK compiles against; they apply when an app resolves a newer one.
-keep @com.google.protobuf.DoNotInline class *
-keepclassmembers,allowshrinking,allowobfuscation class * {
    @com.google.protobuf.DoNotInline *;
}
-assumevalues class com.google.protobuf.Android {
    static boolean ASSUME_ANDROID return true;
    static boolean assumeLiteRuntime return true;
}

# services/store/gpbl/bridges/* resolves billing classes and methods reflectively
# (Class.forName + getMethod) to span the V6/V7/V8 flavors.
 -keep public class com.android.billingclient.api.* {public *;}

# Probed by string name in WorkManagerCapabilitiesChecker; renaming it silently
# disables background work.
-keep class androidx.work.impl.WorkDatabase_Impl { *; }

# Pins the SDK's own workers (DiagnosticEventJob, OperativeEventJob,
# UniversalRequestJob) and the (Context, WorkerParameters) constructor WorkManager
# reflects on. WorkManager persists the worker class name as a string at enqueue
# time, so a rename means work enqueued by an earlier build can no longer be
# instantiated after an app update. Superficially resembles the rules work-runtime
# ships itself -- these were added for a real issue, keep them.
-keep class * extends androidx.work.ListenableWorker {
    <init>(android.content.Context, androidx.work.WorkerParameters);
}
-keep class * extends androidx.work.InputMerger {
    <init>();
}

# Optional dependencies detected by class name in ClassPresenceCapabilitiesChecker.
# If the host app's R8 renames them, the capability is reported missing even though
# the library is present (GH-3654). keepnames only pins the name; the classes stay
# shrinkable when the app does not use them.
-keepnames class androidx.work.WorkManager
-keepnames class androidx.work.impl.WorkDatabase_Impl
-keepnames class org.chromium.net.CronetEngine
-keepnames class org.chromium.net.impl.JavaCronetProvider
-keepnames class okhttp3.OkHttpClient
-keepnames class com.google.android.gms.common.GoogleApiAvailability
-keepnames class com.iab.omid.library.unity3d.Omid
-keepnames class com.android.installreferrer.api.InstallReferrerClient
-keepnames class com.google.android.gms.appset.AppSet
-keepnames class com.google.firebase.installations.FirebaseInstallations
-keepnames class com.android.billingclient.api.BillingClient
-keepnames class com.ironsource.adqualitysdk.sdk.IronSourceAdQuality

# Presence of Android Privacy Sandbox services is handled with runtime checks
# Compile time ProGuard checks can lead to problems with developers (ABT-3131)
-dontwarn android.adservices.**
-dontwarn com.google.android.gms.appset.*
-dontwarn com.google.android.gms.tasks.*
-dontwarn com.android.installreferrer.api.*

-dontwarn com.ironsource.adqualitysdk.**

# Coherence library calls in AndroidCoherenceLibraryManager catch Throwable, so a game that excludes
# coherencelib degrades without crashing. Don't fail the game's R8 build on those references (GH-3812).
-dontwarn com.unity3d.coherence.**
