Skip to content

Commit fdc541c

Browse files
authored
Apply Proguard (#62)
1 parent cc24def commit fdc541c

16 files changed

Lines changed: 442 additions & 160 deletions

File tree

example-app/build.gradle.kts

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,249 @@
1-
plugins {
1+
plugins {
2+
23
alias(libs.plugins.android.application)
4+
35
alias(libs.plugins.kotlin.android)
6+
47
alias(libs.plugins.kotlin.compose)
8+
59
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
10+
611
id("org.jlleitschuh.gradle.ktlint")
712
}
813

914
ktlint {
15+
1016
android.set(true)
17+
1118
reporters {
19+
1220
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
21+
1322
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE)
1423
}
1524
}
1625

1726
android {
27+
1828
namespace = "com.mapconductor.example"
29+
1930
compileSdk = project.property("compileSdk").toString().toInt()
2031

2132
defaultConfig {
33+
2234
applicationId = "com.mapconductor.example"
35+
2336
minSdk = project.property("minSdk").toString().toInt()
37+
2438
targetSdk = project.property("targetSdk").toString().toInt()
39+
ndk { abiFilters += listOf("arm64-v8a") }
40+
vectorDrawables {
41+
useSupportLibrary = true
42+
}
43+
2544
versionCode = 1
45+
2646
versionName = "1.0"
47+
2748
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2849
}
2950

3051
composeOptions {
52+
3153
kotlinCompilerExtensionVersion =
54+
3255
project.property("kotlinCompilerExtensionVersion").toString()
3356
}
3457

3558
buildTypes {
59+
60+
debug {
61+
62+
isMinifyEnabled = false
63+
64+
proguardFiles(
65+
getDefaultProguardFile("proguard-android.txt"),
66+
"proguard-rules.pro",
67+
)
68+
}
69+
3670
release {
37-
isMinifyEnabled = project.property("isMinifyEnabled").toString().toBoolean()
71+
72+
isMinifyEnabled = true
73+
74+
isShrinkResources = true
75+
3876
proguardFiles(
3977
getDefaultProguardFile("proguard-android-optimize.txt"),
4078
"proguard-rules.pro",
4179
)
80+
81+
// Force legacy ProGuard instead of R8
82+
83+
buildConfigField("String", "BUILD_CONFIG_VERSION", "\"release\"")
84+
signingConfig = signingConfigs.getByName("debug")
4285
}
4386
}
87+
88+
packaging {
89+
90+
resources {
91+
92+
excludes += "META-INF/versions/9/previous-compilation-data.bin"
93+
excludes += "META-INF/*.kotlin_module"
94+
excludes += "META-INF/AL2.0"
95+
excludes += "META-INF/LGPL2.1"
96+
excludes += "META-INF/androidx.*.version"
97+
excludes += "**/*.proto"
98+
}
99+
100+
jniLibs {
101+
useLegacyPackaging = true
102+
}
103+
}
104+
44105
compileOptions {
106+
45107
sourceCompatibility = JavaVersion.toVersion(project.property("javaVersion").toString())
108+
46109
targetCompatibility = JavaVersion.toVersion(project.property("javaVersion").toString())
47110
}
111+
48112
kotlinOptions {
113+
49114
jvmTarget = project.property("jvmTarget").toString()
50115
}
116+
51117
buildFeatures {
118+
52119
compose = true
120+
121+
buildConfig = true
53122
}
123+
124+
bundle {
125+
language {
126+
enableSplit = true
127+
}
128+
density {
129+
enableSplit = true
130+
}
131+
abi {
132+
enableSplit = true
133+
}
134+
}
135+
54136
testOptions {
137+
55138
unitTests {
139+
56140
isIncludeAndroidResources = true
57141
}
58142
}
59143
}
144+
60145
secrets {
146+
61147
// To add your Maps API key to this project:
148+
62149
// 1. If the secrets.properties file does not exist, create it in the same folder as the local.properties file.
150+
63151
// 2. Add this line, where YOUR_API_KEY is your API key:
152+
64153
// MAPS_API_KEY=YOUR_API_KEY
154+
65155
propertiesFileName = "secrets.properties"
66156

67157
// A properties file containing default secret values. This file can be
158+
68159
// checked in version control.
160+
69161
defaultPropertiesFileName = "local.defaults.properties"
70162
}
71163

72164
dependencies {
73165

74166
implementation(libs.androidx.core.ktx)
167+
75168
implementation(libs.androidx.lifecycle.runtime.ktx)
169+
76170
implementation(libs.androidx.activity.compose)
171+
77172
implementation(libs.androidx.lifecycle.viewmodel.compose)
173+
78174
implementation(platform(libs.androidx.compose.bom))
175+
79176
implementation(libs.androidx.ui)
177+
80178
implementation(libs.androidx.ui.graphics)
179+
81180
implementation(libs.androidx.ui.tooling.preview)
181+
82182
implementation(libs.androidx.material3)
183+
83184
implementation(libs.androidx.appcompat)
185+
84186
implementation(platform(libs.firebase.bom))
85187

86188
// Google Maps SDK
189+
87190
implementation(libs.play.services.maps)
191+
88192
// Here Maps SDK
193+
89194
val hereSdkAarName: String by project
195+
90196
implementation(files("${rootProject.projectDir}/libs/$hereSdkAarName.aar"))
197+
91198
// Mapbox SDK
199+
92200
implementation(libs.mapbox.android)
93201

94202
// ArcGIS Maps for Kotlin - SDK dependency
203+
95204
implementation(libs.arcgis.maps.kotlin)
205+
96206
implementation(platform(libs.arcgis.maps.kotlin.toolkit.bom))
207+
97208
implementation(libs.arcgis.maps.kotlin.toolkit.geoview.compose)
209+
98210
implementation(libs.arcgis.maps.kotlin.toolkit.authentication)
99211

100212
// Map Conductor
213+
101214
implementation(project(":mapconductor-core"))
215+
102216
implementation(project(":mapconductor-icons"))
217+
103218
implementation(project(":mapconductor-for-googlemaps"))
219+
104220
implementation(project(":mapconductor-for-here"))
221+
105222
implementation(project(":mapconductor-for-mapbox"))
223+
106224
implementation(project(":mapconductor-for-arcgis"))
225+
107226
implementation(libs.androidx.vectordrawable)
227+
108228
implementation(libs.androidx.room.runtime.android)
109229

110230
testImplementation(libs.junit)
231+
111232
testImplementation(libs.androidx.core)
233+
112234
testImplementation(libs.androidx.junit)
235+
113236
testImplementation(libs.androidx.runner)
237+
114238
androidTestImplementation(libs.androidx.junit)
239+
115240
androidTestImplementation(libs.androidx.espresso.core)
241+
116242
androidTestImplementation(platform(libs.androidx.compose.bom))
243+
117244
androidTestImplementation(libs.androidx.ui.test.junit4)
245+
118246
debugImplementation(libs.androidx.ui.tooling)
247+
119248
debugImplementation(libs.androidx.ui.test.manifest)
120249
}

example-app/proguard-rules.pro

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,65 @@
1-
# Add project specific ProGuard rules here.
2-
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.
4-
#
5-
# For more details, see
6-
# http://developer.android.com/guide/developing/tools/proguard.html
7-
8-
# If your project uses WebView with JS, uncomment the following
9-
# and specify the fully qualified class name to the JavaScript interface
10-
# class:
11-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12-
# public *;
13-
#}
14-
15-
# Uncomment this to preserve the line number information for
16-
# debugging stack traces.
17-
#-keepattributes SourceFile,LineNumberTable
18-
19-
# If you keep the line number information, uncomment this to
20-
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
1+
# MapConductor Example App ProGuard Rules
2+
3+
# Keep line number information for debugging stack traces
4+
-keepattributes SourceFile,LineNumberTable
5+
6+
# Optimization settings
7+
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
8+
-optimizationpasses 5
9+
-allowaccessmodification
10+
-dontpreverify
11+
12+
# Obfuscation settings (remove -dontobfuscate for better compression)
13+
-repackageclasses ''
14+
-allowaccessmodification
15+
16+
# Keep essential Android classes
17+
-keep public class * extends android.app.Activity
18+
-keep public class * extends android.app.Application
19+
-keep public class * extends android.app.Service
20+
-keep public class * extends android.content.BroadcastReceiver
21+
-keep public class * extends android.content.ContentProvider
22+
23+
# Keep Compose essentials only
24+
-keep class androidx.compose.runtime.Composable
25+
-keep class * extends androidx.activity.ComponentActivity {
26+
public <init>(...);
27+
}
28+
29+
# Keep ViewModel constructors
30+
-keep class * extends androidx.lifecycle.ViewModel {
31+
<init>(...);
32+
}
33+
34+
# Keep only essential MapConductor classes
35+
-keep class com.mapconductor.example.MainActivity { *; }
36+
-keep class com.mapconductor.example.MapConductorExampleApplication { *; }
37+
38+
# Keep data classes used in UI
39+
-keepclassmembers class com.mapconductor.example.pages.stores.DemoData {
40+
<fields>;
41+
<methods>;
42+
}
43+
44+
# Keep Parcelable implementations
45+
-keep class * implements android.os.Parcelable {
46+
public static final android.os.Parcelable$Creator *;
47+
}
48+
49+
# Keep serialization
50+
-keepattributes Signature
51+
-keepclassmembers class * implements java.io.Serializable {
52+
static final long serialVersionUID;
53+
private static final java.io.ObjectStreamField[] serialPersistentFields;
54+
private void writeObject(java.io.ObjectOutputStream);
55+
private void readObject(java.io.ObjectInputStream);
56+
java.lang.Object writeReplace();
57+
java.lang.Object readResolve();
58+
}
59+
60+
# Remove logging in release builds
61+
-assumenosideeffects class android.util.Log {
62+
public static *** d(...);
63+
public static *** v(...);
64+
public static *** i(...);
65+
}

gradle.properties

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Project-wide Gradle settings.
1+
# Project-wide Gradle settings.
22
# IDE (e.g. Android Studio) users:
33
# Gradle settings configured through the IDE *will override*
44
# any settings specified in this file.
@@ -32,4 +32,8 @@ versionCode=1
3232
versionName=1.0.0
3333
javaVersion=11
3434
jvmTarget=11
35-
isMinifyEnabled=false
35+
isMinifyEnabled=true
36+
# R8 settings for handling duplicate classes
37+
android.enableR8.fullMode=true
38+
android.r8.ignoreAllowListBinaryFiles=true
39+
android.enableJetifier=true

mapconductor-core/build.gradle.kts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plugins {
1+
plugins {
22
id("com.android.library")
33
id("org.jetbrains.kotlin.android")
44
id("maven-publish")
@@ -21,6 +21,7 @@ android {
2121
defaultConfig {
2222
minSdk = project.property("minSdk").toString().toInt()
2323
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
24+
consumerProguardFiles("consumer-rules.pro")
2425
}
2526

2627
buildFeatures {
@@ -32,10 +33,17 @@ android {
3233
}
3334

3435
buildTypes {
36+
debug {
37+
isMinifyEnabled = false
38+
proguardFiles(
39+
getDefaultProguardFile("proguard-android.txt"),
40+
"proguard-rules.pro",
41+
)
42+
}
3543
release {
36-
isMinifyEnabled = project.property("isMinifyEnabled").toString().toBoolean()
44+
isMinifyEnabled = false
3745
proguardFiles(
38-
getDefaultProguardFile("proguard-android-optimize.txt"),
46+
getDefaultProguardFile("proguard-android.txt"),
3947
"proguard-rules.pro",
4048
)
4149
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Keep Settings and its nested classes for consumers
2+
-keep class com.mapconductor.settings.Settings { *; }
3+
-keep class com.mapconductor.settings.Settings$* { *; }

0 commit comments

Comments
 (0)