From c84f209bec7b399a55f067449b6df0d427c31c88 Mon Sep 17 00:00:00 2001 From: Leonidius20 <25536411+Leonidius20@users.noreply.github.com> Date: Tue, 30 Jan 2024 23:14:53 +0200 Subject: [PATCH] disabled minification due to retrofit issues --- app/build.gradle.kts | 14 +++- app/proguard-rules.pro | 78 ++++++++++++++++++- .../beatinspector/BeatInspectorApp.kt | 1 + data/proguard-rules.pro | 53 +++++++------ gradle.properties | 4 +- settings.gradle.kts | 1 + 6 files changed, 122 insertions(+), 29 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 80065c2..ab937df 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -23,6 +23,8 @@ android { useSupportLibrary = true } + resourceConfigurations.addAll(listOf("en")) // only english resources + val keystoreFile = project.rootProject.file("secrets.properties") @@ -30,7 +32,7 @@ android { val secretProperties = Properties() secretProperties.load(keystoreFile.inputStream()) - val clientId = secretProperties.getProperty("SPOTIFY_CLIENT_ID") ?: "" + val clientId = secretProperties.getProperty("SPOTIFY_CLIENT_ID") ?: throw Exception("SPOTIFY_CLIENT_ID not set in secrets.properties") buildConfigField("String", "SPOTIFY_CLIENT_ID", "\"$clientId\"") } else { @@ -70,8 +72,8 @@ android { buildTypes { release { - isMinifyEnabled = true - isShrinkResources = true + isMinifyEnabled = false // due to retrofit r8 issues + isShrinkResources = false proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") signingConfig = signingConfigs.getByName("release") } @@ -116,7 +118,7 @@ dependencies { implementation("androidx.navigation:navigation-compose:$nav_version") - implementation("com.squareup.retrofit2:retrofit:2.9.0") + implementation("com.squareup.retrofit2:retrofit:2.10.0-SNAPSHOT") // implementation("com.google.code.gson:gson:2.8.9") implementation("com.squareup.retrofit2:converter-gson:2.9.0") @@ -128,6 +130,10 @@ dependencies { implementation("com.github.haroldadmin:NetworkResponseAdapter:5.0.0") + // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp + implementation("com.squareup.okhttp3:okhttp:4.12.0") + + implementation(project(":data")) testImplementation("junit:junit:4.13.2") diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..4bb6f7e 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,4 +18,80 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile +-printconfiguration ./build/app-full-r8-config.txt +-printusage ./build/app-full-r8-usage.txt +-printseeds ./build/app-full-r8-seeds.txt +-keepattributes LineNumberTable,SourceFile +-renamesourcefileattribute SourceFile + + +-dontobfuscate + + + + + + + + + + + + + + + + + + + +# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and +# EnclosingMethod is required to use InnerClasses. +-keepattributes Signature, InnerClasses, EnclosingMethod + +# 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.* ; +} + +# 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.* ; } +-keep,allowobfuscation interface <1> + +# Keep inherited services. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface * extends <1> + +# 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 + +# R8 full mode strips generic signatures from return types if not kept. +-if interface * { @retrofit2.http.* public *** *(...); } +-keep,allowoptimization,allowshrinking,allowobfuscation class <3> + +# With R8 full mode generic signatures are stripped for classes that are not kept. +-keep,allowobfuscation,allowshrinking class retrofit2.Response + diff --git a/app/src/main/java/ua/leonidius/beatinspector/BeatInspectorApp.kt b/app/src/main/java/ua/leonidius/beatinspector/BeatInspectorApp.kt index 3cf5510..b3025cd 100644 --- a/app/src/main/java/ua/leonidius/beatinspector/BeatInspectorApp.kt +++ b/app/src/main/java/ua/leonidius/beatinspector/BeatInspectorApp.kt @@ -34,6 +34,7 @@ class BeatInspectorApp: Application() { .addConverterFactory(GsonConverterFactory. create()) .addCallAdapterFactory(NetworkResponseAdapterFactory()) .client( + OkHttpClient.Builder() .addInterceptor(authInterceptor) .build()) diff --git a/data/proguard-rules.pro b/data/proguard-rules.pro index ec08675..373256b 100644 --- a/data/proguard-rules.pro +++ b/data/proguard-rules.pro @@ -19,6 +19,36 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + + +-printconfiguration ./build/data-full-r8-config.txt +-printusage ./build/data-full-r8-usage.txt +-printseeds ./build/data-full-r8-seeds.txt +-keepattributes LineNumberTable,SourceFile +-renamesourcefileattribute SourceFile + + +-dontobfuscate + + + + + + + + + + + + + + + + + + + + # Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and # EnclosingMethod is required to use InnerClasses. @@ -68,26 +98,3 @@ # With R8 full mode generic signatures are stripped for classes that are not kept. -keep,allowobfuscation,allowshrinking class retrofit2.Response - - - - -# for okhttp -# JSR 305 annotations are for embedding nullability information. --dontwarn javax.annotation.** - -# A resource is loaded with a relative path so the package of this class must be preserved. --adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz - -# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java. --dontwarn org.codehaus.mojo.animal_sniffer.* - -# OkHttp platform used only on JVM and when Conscrypt and other security providers are available. --dontwarn okhttp3.internal.platform.** --dontwarn org.conscrypt.** --dontwarn org.bouncycastle.** --dontwarn org.openjsse.** - - -# FOR Its dependency --dontwarn okio.** \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 582e6f8..a83beed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,4 +21,6 @@ kotlin.code.style=official # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true -org.gradle.unsafe.configuration-cache=true \ No newline at end of file +org.gradle.unsafe.configuration-cache=true + +android.enableR8.fullMode=false \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index cffdb15..552d345 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ dependencyResolutionManagement { google() mavenCentral() maven("https://jitpack.io") + maven("https://s01.oss.sonatype.org/content/repositories/snapshots") } }