# \[Android]難読化・最適化に対応する

R8を用いて、アプリを難読化・最適化する場合に、SDKのメソッドが難読化・最適化され正常に動作しない場合があります。

## アプリ内メッセージを使用する場合

### inappmessaging 2.8.0以上を使用している場合

aarファイル内のProGuard設定を参照したビルドが可能な場合、特に対応は不要です。\
Gradleでビルドする際にはデフォルトでこの挙動になっています。

### inappmessaging 2.8.0未満を使用している場合

アプリのProGuard設定に下記設定を追記して下さい。

{% code title="proguard-rules.pro" overflow="wrap" %}

```
-keepclassmembers class io.karte.android.inappmessaging.** {
    @android.webkit.JavascriptInterface <methods>;
}
```

{% endcode %}

## その他の機能のみ使用する場合

アプリ内メッセージ以外の機能では、特に難読化・最適化の影響を受けないことを確認しています。

## R8ではなくProGuardを使用する場合

Android Gradle Pluginの3.5.0以降では、デフォルトで難読化ツールとして、R8を使用するようになっています。\
アプリ側の何らかの事情でProGuardを使用しなくてはならない場合、SDK用の設定が必要です。

**参考：設定例**

{% code title="proguard-rules.pro" overflow="wrap" %}

```
-dontwarn io.karte.android.**
-keep class io.karte.android.core.library.Library
-keep class * extends io.karte.android.core.library.Library
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://app.developers.karte.io/android-sdk-appendix/appendix-proguard-android-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
