> For the complete documentation index, see [llms.txt](https://developers.didomi.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.didomi.io/cmp/mobile-sdk/android/setup/proguard-r8-rules.md).

# ProGuard/R8 rules

Proguard (and its successor, R8) is a code-shrinking and obfuscation tool used by Android when building release apps. Without the necessary rules in place, Proguard might strip or rename classes that an SDK needs at runtime that causes app crashes.

The Didomi Android SDK includes ProGuard rules in its Android Archive (AAR) that is automatically applied to any Android application that integrates the SDK. Your organization does not need to copy or references these rules manually as they will take effect at build time. In this article, we provide an overview of the different ProGuard/R8 rules that are packaged with the Didomi Android SDK:

* [Core Didomi SDK classes rules](#core-didomi-sdk-classes-rules)
* [Defensive/housekeeping rules](#defensive-housekeeping-rules)
* [Gson rules](#gson-rules)
* [Firebase rules](#firebase-rules)

{% hint style="info" %}
If your organization has a custom ProGuard configuration that conflicts (e.g. aggresive `-keep` or `-obfuscate` overrides) it my need to verify that these rules are not being overridden.
{% endhint %}

### Core Didomi SDK classes rules

The following rules tell ProGuard to leave Didomi SDK classes untouched (they should not be removed nor renamed):

```
-keep class io.didomi.iabtcf.** { *; }
-keep class io.didomi.sdk.** { *; }
```

### Defensive/housekeeping rules

<table><thead><tr><th width="401.06658935546875">Rule</th><th>Description</th></tr></thead><tbody><tr><td><pre data-overflow="wrap"><code>-keep,allowshrinking,allowobfuscation enum io.didomi.iabtcf.decoder.v2.RestrictionType
</code></pre></td><td>Preserves a specific enum used in TCF v2 decoding to work around a known bug in certain ProGuard versions</td></tr><tr><td><pre data-overflow="wrap"><code>-dontwarn com.eclipsesource.v8.V8
</code></pre></td><td>Suppresses a build warning about <code>V8</code> (a JavaScript engine). The SDK no longer depends on <code>V8</code> at runtime, but a reference may linger in the dependency tree.</td></tr><tr><td><pre data-overflow="wrap"><code>-dontwarn kotlinx.parcelize.Parcelize
</code></pre></td><td>Suppresses a warning about Kotlin's <code>@Parcelize</code> annotation plugin in certain build configurations.</td></tr></tbody></table>

### Gson rules

The following rules are used to handle Gson:

<table><thead><tr><th>Rule</th><th>Description</th></tr></thead><tbody><tr><td><pre data-overflow="wrap"><code>-keepattributes Signature
</code></pre></td><td>Preserves generic type information Gson needs to read JSON into typed objects</td></tr><tr><td><pre data-overflow="wrap"><code>-keepattributes *Annotation*
</code></pre></td><td>Keeps <code>@Expose</code> and other Gson annotations</td></tr><tr><td><pre data-overflow="wrap"><code>-dontwarn sun.misc.**
</code></pre></td><td>Suppresses a known harmless warning from Gson internals</td></tr><tr><td><pre data-overflow="wrap"><code>-keep class * extends com.google.gson.TypeAdapter
</code></pre></td><td>Protects custom JSON adapters from being stripped</td></tr><tr><td><pre data-overflow="wrap"><code>-keep class * implements com.google.gson.TypeAdapterFactory
</code></pre></td><td>Protects custom JSON adapter factories from being stripped</td></tr><tr><td><pre data-overflow="wrap"><code>-keep class * implements com.google.gson.JsonSerializer/Deserializer
</code></pre></td><td>Protects custom serializer/deserializer implementations</td></tr><tr><td><pre data-overflow="wrap"><code>-keepclassmembers … @SerializedName
</code></pre></td><td>Prevents R8 from nullifying fields mapped from JSON using the <code>@SerializedName</code> annotation</td></tr><tr><td><pre data-overflow="wrap"><code>-keep class com.google.gson.reflect.TypeToken
</code></pre></td><td>Required for R8 v3.0+ to correctly handle generic type tokens</td></tr></tbody></table>

### Firebase rules

The following rules apply to Android applications that use the Didomi Android SDK and Firebase Analytics with Google Consent Mode v2 enabled. Together, these rules protect Firebase Analytics classes that the Didomi Android SDK's Google Consent Mode v2 integration calls via reflection.

{% hint style="info" %}
Reflection is a technique where code calls another class's methods by name at runtime rather than at compile time. This technique requires explicit ProGuard protection.
{% endhint %}

{% code overflow="wrap" %}

```
-dontwarn com.google.firebase.analytics.FirebaseAnalytics
-keep class com.google.firebase.analytics.FirebaseAnalytics$ConsentType { *; }
-keep class com.google.firebase.analytics.FirebaseAnalytics$ConsentStatus { *; }
-keepclassmembers class com.google.firebase.analytics.FirebaseAnalytics {
    public void setConsent(java.util.Map);
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.didomi.io/cmp/mobile-sdk/android/setup/proguard-r8-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
