Skip to content

Commit

Permalink
Merge pull request #98 from /issues/49-minify-enabled
Browse files Browse the repository at this point in the history
Add rules for Proguard
  • Loading branch information
onthecrow authored Nov 15, 2023
2 parents 218648a + 9a34dbf commit 9d050c8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
[malware protection](https://uploadcare.com/docs/security/malware-protection/),
and [background removal](https://uploadcare.com/docs/remove-bg/).
- Fixed authorization signature for requests with url parameters.
- Added Proguard rule to keep DTO classes to avoid issues with network JSON deserialization.
- Widget:
- SocialApi doesn't use `GET /sources` method anymore.
- Added Proguard rule to keep DTO classes to avoid issues with network JSON deserialization.
- Project:
- Migrated Gradle builds from Groovy to Kotlin.
- Example:
- Removed sorting options by file size from `UploadFragment`.
- Enable R8 shrinking code for release build to enable Proguard's rules.

## 3.3.0
- Library:
Expand Down
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
repositories {
maven(url = "https://maven.google.com")
maven(url = "https://storage.googleapis.com/r8-releases/raw")
google()
mavenCentral()
}
Expand All @@ -12,6 +13,10 @@ buildscript {
classpath("com.android.tools.build:gradle:${libs.versions.gradleVersion.get()}")
classpath(libs.kotlin.plugin)
classpath(libs.navigation.safe.args.plugin)

// Required to support for sealed classes until AGP 8.2
// https://issuetracker.google.com/issues/227160052#comment37
classpath(libs.tools.r8)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {

buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ moshi = "1.15.0"
junit = "4.13.2"
testRunner = "1.5.2"
espressoCore = "3.5.1"
r8 = "8.2.36"

[libraries]
kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlinVersion" }
Expand Down Expand Up @@ -67,3 +68,5 @@ preference-ktx = { group = "androidx.preference", name = "preference-ktx", versi
test-runner = { group = "androidx.test", name = "runner", version.ref = "testRunner" }
test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
test-junit = { group = "junit", name = "junit", version.ref = "junit" }

tools-r8 = { module = "com.android.tools:r8", version.ref = "r8" }
3 changes: 2 additions & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ android {

buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
consumerProguardFile("proguard-rules.pro")
}
}
packaging {
Expand Down
9 changes: 9 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-dontwarn java.lang.invoke.StringConcatFactory

-keep class com.uploadcare.android.library.data.** { *; }
-keep class com.uploadcare.android.library.api.Project { *; }
-keep class com.uploadcare.android.library.api.UploadcareCopyFile { *; }
-keep class com.uploadcare.android.library.api.UploadcareFile { *; }
-keep class com.uploadcare.android.library.api.UploadcareGroup { *; }
-keep class com.uploadcare.android.library.api.UploadcareWebhook { *; }
3 changes: 2 additions & 1 deletion widget/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ android {
buildConfigField("String", "SOCIAL_API_ENDPOINT", "\"https://social.uploadcare.com/\"")
}
release {
isMinifyEnabled = false
isMinifyEnabled = true
buildConfigField("String", "SOCIAL_API_ENDPOINT", "\"https://social.uploadcare.com/\"")
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
consumerProguardFile("proguard-rules.pro")
}
}

Expand Down
18 changes: 18 additions & 0 deletions widget/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keep class com.uploadcare.android.widget.data.** { *; }

# Keep inherited services.
-if interface * { @retrofit2.http.* <methods>; }
-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

0 comments on commit 9d050c8

Please sign in to comment.