Skip to content

Commit

Permalink
AND-8870 Setup R8 obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeeei committed Nov 20, 2024
1 parent 506912a commit 68dbc2b
Show file tree
Hide file tree
Showing 62 changed files with 582 additions and 191 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.tangem.plugin.configuration.configurations.extension.kaptForObfuscatingVariants

plugins {
alias(deps.plugins.android.application)
alias(deps.plugins.kotlin.android)
Expand Down Expand Up @@ -232,6 +234,10 @@ dependencies {
implementation(deps.walletConnectWeb3)
implementation(deps.prettyLogger)

implementation(deps.moshi.kotlin)
kaptForObfuscatingVariants(deps.moshi.kotlin.codegen)
kaptForObfuscatingVariants(deps.retrofit.response.type.keeper)

/** Testing libraries */
testImplementation(deps.test.coroutine)
testImplementation(deps.test.junit)
Expand Down Expand Up @@ -270,5 +276,4 @@ dependencies {
// excludes version 9999.0-empty-to-avoid-conflict-with-guava
exclude(group = "com.google.guava", module = "listenablefuture")
}

}
202 changes: 181 additions & 21 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,21 +1,181 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-optimizationpasses 5
-dontusemixedcaseclassnames
-flattenpackagehierarchy
-adaptclassstrings
-verbose

# firebase
-keep public class com.google.firebase.** { *; }
-keep class com.google.android.gms.internal.** { *; }
-keepclasseswithmembers class com.google.firebase.FirebaseException

# hedera sdk
-keep class com.hedera.hashgraph.sdk.** { *; }
-keep interface com.hedera.hashgraph.sdk.** { *; }
-dontwarn com.esaulpaugh.headlong.**
-dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings
-dontwarn io.grpc.stub.**

# trustwallet sdk
-keep class wallet.core.jni.** { *; }

# solana
-keep class org.p2p.solanaj.** { *; }

# kethereum
-keep class org.kethereum.bip32.model.ExtendedKey**
-keepclassmembers class org.kethereum.bip32.model.ExtendedKey** { *; }

# some crypto
-dontwarn net.i2p.crypto.**
-dontwarn java.net.http.**
-dontwarn lombok.**

-dontwarn org.apache.hc.core5.**
-dontwarn org.apache.hc.client5.**
-dontwarn org.apache.log4j.config.**

-dontwarn javax.xml.stream.**
-dontwarn javax.script.**

-dontwarn aQute.bnd.annotation.spi.ServiceProvider

-dontwarn org.threeten.bp.**
-keep class org.threeten.bp.zone.*
-keep class org.threeten.bp.*
-keepclassmembers class org.threeten.bp.** { *; }

# joda time
# These aren't necessary if including joda-convert
-dontwarn org.joda.convert.FromString
-dontwarn org.joda.convert.ToString

-keepnames class org.joda.** implements java.io.Serializable
-keepclassmembers class org.joda.** implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# joda time

# Enum field names are used by the integrated EnumJsonAdapter.
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
**[] values();
}

# Keep helper method to avoid R8 optimisation that would keep all Kotlin Metadata when unwanted
-keepclassmembers class com.squareup.moshi.internal.Util {
private static java.lang.String getKotlinMetadataClassName();
}

-keep class kotlin.Metadata { *; }
-keepclassmembers class kotlin.Metadata {
public <methods>;
}

-keepclasseswithmembers class * {
@com.squareup.moshi.* <methods>;
}

-keep @com.squareup.moshi.JsonQualifier interface *

-keepclassmembers class * {
@com.squareup.moshi.FromJson <methods>;
@com.squareup.moshi.ToJson <methods>;
}

# Proguard configuration for Jackson 2.x
-keep class com.fasterxml.** { *; }
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep class * implements com.fasterxml.jackson.core.type.TypeReference

-keep class kotlin.reflect.**
-keep public class kotlin.reflect.jvm.internal.impl.** { public *; }

# Kotlin serialization looks up the generated serializer classes through a function on companion
# objects. The companions are looked up reflectively so we need to explicitly keep these functions.
-keepclasseswithmembers class **.*$Companion {
kotlinx.serialization.KSerializer serializer(...);
}
# If a companion has the serializer function, keep the companion field on the original type so that
# the reflective lookup succeeds.
-if class **.*$Companion {
kotlinx.serialization.KSerializer serializer(...);
}
-keepclassmembers class <1>.<2> {
<1>.<2>$Companion Companion;
}

-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-dontwarn okhttp3.**
-dontwarn okio.**

# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod, *Annotation*, Exceptions

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}

-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
-keepclassmembernames interface * {
@retrofit.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions.*

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package com.tangem.tap.domain.userWalletList.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.wallets.models.UserWalletId

@JsonClass(generateAdapter = true)
internal data class UserWalletSensitiveInformation(
@Json(name = "wallets")
val wallets: List<CardDTO.Wallet>,
)

@JsonClass(generateAdapter = true)
internal data class UserWalletPublicInformation(
@Json(name = "name")
val name: String,
@Json(name = "walletId")
val walletId: UserWalletId,
@Json(name = "artworkUrl")
val artworkUrl: String,
@Json(name = "cardsInWallet")
val cardsInWallet: Set<String>,
@Json(name = "scanResponse")
val scanResponse: ScanResponse,
@Json(name = "isMultiCurrency")
val isMultiCurrency: Boolean,
@Json(name = "hasBackupError")
val hasBackupError: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ data class WcSignMessage(
@Json(name = "type")
val type: WCSignType,
) : WcRequestData {

@JsonClass(generateAdapter = false)
enum class WCSignType {
MESSAGE, PERSONAL_MESSAGE, TYPED_MESSAGE, SOLANA_MESSAGE,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
package com.tangem.tap.domain.walletconnect2.domain.models

data class Account(val chainId: String, val walletAddress: String, val derivationPath: String?)
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Account(
@Json(name = "chainId")
val chainId: String,

@Json(name = "walletAddress")
val walletAddress: String,

@Json(name = "derivationPath")
val derivationPath: String?,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.tangem.tap.domain.walletconnect2.domain.models

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Session(
@Json(name = "topic")
val topic: String,

@Json(name = "accounts")
val accounts: List<Account>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@ package com.tangem.tap.domain.walletconnect2.domain.models.binance

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.tap.domain.walletconnect2.domain.WcRequestData

@Suppress("LongParameterList")
@JsonClass(generateAdapter = true)
class WcBinanceCancelOrder(
data class WcBinanceCancelOrder(
@Json(name = "account_number")
accountNumber: String,
val accountNumber: String,
@Json(name = "chain_id")
chainId: String,
val chainId: String,
@Json(name = "data")
data: String?,
val data: String?,
@Json(name = "memo")
memo: String?,
val memo: String?,
@Json(name = "sequence")
sequence: String,
val sequence: String,
@Json(name = "source")
source: String,
val source: String,
@Json(name = "msgs")
msgs: List<Message>,
) : WcBinanceOrder<WcBinanceCancelOrder.Message>(accountNumber, chainId, data, memo, sequence, source, msgs) {
val msgs: List<Message>,
) : WcRequestData {

@JsonClass(generateAdapter = true)
data class Message(
@Json(name = "refid")
val refid: String,
@Json(name = "sender")
val sender: String,
@Json(name = "symbol")
val symbol: String,
)
}

This file was deleted.

Loading

0 comments on commit 68dbc2b

Please sign in to comment.