Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rules for Proguard #98

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
- Added support for converting multipage into a group of files.
- Added `default_effects` field in `UploadcareFile`.
- Added react to request throttling (429 code response).
- Added rules for Proguard.
CheK539 marked this conversation as resolved.
Show resolved Hide resolved
- Widget:
- SocialApi doesn't use `GET /sources` method anymore.
- Added rules for Proguard.
- Project:
- Migrated Gradle builds from Groovy to Kotlin.
- Example:
- Removed sorting options by file size from `UploadFragment`.
- Enable R8 shrinking code for release build.

## 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