Skip to content

Commit

Permalink
Optimize and fix android dependencies (#299)
Browse files Browse the repository at this point in the history
* upgrade libraries and remove unused ones

* - remove AppCompat and Material Components.
- set the Android theme colors to match the compose theme colors on app startup.

* - remove Firebase in-app messaging which depends on Glide an AppCompat
- remove Koin-Android dependency which is not needed when adding Koin-Androidx-Compose dependency.

* remove unused Coil image loader

* remove transitive dependencies to AppCompat for Precompose, Moko and Koin

* add missing core library desugaring for the Android app (to properly support kotlinx.datetime on API < 26)

* replace default Proguard rules with more optimized ones (enabling R8 optimizations) and remove unnecessary rules

* disable Kotlin assertions for release builds and remove unnecessary packaged files

* disable Android DI debug logging from release builds

* remove AppCompat version

* remove unused compose-material library (only compose-material3 is used)

* remove unused Kotlin Serialization plugin

* align all compose versions together to ensure the best compatibility with Compose Multiplatform 1.6.2

* remove unused navigation-compose library from the Android app

* fix Compose dependencies of the Wear app

* fix Apollo version and downgrade to 4.0.0-beta.2 which doesn't depend on Kotlin 2.0.0 (the project depends on Kotlin 1.9.23)

* disable support vector drawables for Wear because minSDK is >24

* add missing Proguard defaults for Wear

* exclude unused packaged files an jni libs, and update compiler arguments for Wear release builds

* switch to horologist 0.5.25 which is the version designed for Wear Compose 1.3.x and Compose 1.6.4 currently used in the project
  • Loading branch information
cbeyls authored Apr 27, 2024
1 parent 1c5fa0b commit e940908
Show file tree
Hide file tree
Showing 23 changed files with 220 additions and 149 deletions.
52 changes: 41 additions & 11 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,69 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
}

buildFeatures.buildConfig = true

buildTypes {
release {
kotlinOptions {
freeCompilerArgs += listOf(
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"
)
}

packaging {
resources {
excludes += listOf(
"DebugProbesKt.bin",
"kotlin-tooling-metadata.json",
"/*.properties",
"kotlin/**",
"junit/**",
"LICENSE-junit.txt",
"/*.proto",
"google/**",
"META-INF/*.version"
)
}
jniLibs {
excludes += "**/libdatastore_shared_counter.so"
}
}
}
}
}

dependencies {
implementation(project(":shared:data"))
testImplementation(libs.junit)
androidTestImplementation(libs.espresso.core)

coreLibraryDesugaring(libs.desugar.jdk.libs)

// Kotlin
implementation(libs.kotlinx.coroutines.play.services)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)

// Support
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.activity)
implementation(libs.androidx.appcompat)

implementation(libs.material)
implementation(libs.androidx.lifecycle.runtime)

// Firebase
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.crashlytics.ktx)
implementation(libs.firebase.inappmessaging)
implementation(libs.firebase.messaging)

implementation(libs.play.services.auth)

// Image management
implementation(libs.coil.compose)

implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.koin.androidx.compose) {
exclude(group = "androidx.appcompat", module = "appcompat")
}

// Used for tags
implementation(project(":shared"))
Expand Down
40 changes: 40 additions & 0 deletions androidApp/proguard-defaults.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Less conservative default ProGuard rules
-allowaccessmodification

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Preserve some attributes that may be required for reflection.
-keepattributes RuntimeVisible*Annotations, AnnotationDefault

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}

-keepclassmembers,allowoptimization enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}

# Preserve annotated Javascript interface methods.
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}

# The support libraries contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontnote androidx.**
-dontwarn androidx.**

# This class is deprecated, but remains for backward compatibility.
-dontwarn android.util.FloatMath

# These classes are duplicated between android.jar and core-lambda-stubs.jar.
-dontnote java.lang.invoke.**
15 changes: 0 additions & 15 deletions androidApp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}

-dontwarn org.slf4j.**

-keep class fr.androidmakers.store.model.** { *; }
-keep class io.openfeedback.android.model.** { *; }

-keepattributes Signature

-dontwarn com.google.ar.**
3 changes: 1 addition & 2 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:name=".AndroidMakersApplication"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/PreviewTheme.AndroidMakers"
android:theme="@style/Theme.AndroidMakers"
tools:ignore="UnusedAttribute">

<meta-data
Expand All @@ -37,7 +37,6 @@
android:launchMode="singleTask"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AndroidMakers.NoActionBar"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
Expand Down Expand Up @@ -37,7 +37,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.compose.KoinContext

class MainActivity : AppCompatActivity() {
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
8 changes: 3 additions & 5 deletions androidApp/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.AndroidMakers" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<style name="Theme.AndroidMakers" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowBackground">@color/backgroundDark</item>
</style>

<style name="Theme.AndroidMakers.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar"></style>
</resources>
12 changes: 0 additions & 12 deletions androidApp/src/main/res/values-v21/themes_preview.xml

This file was deleted.

9 changes: 2 additions & 7 deletions androidApp/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#4eb6e3</color>
<color name="colorPrimaryDark">#16A6D9</color>
<color name="colorAccent">#E85145</color>
<color name="bottom">#ECEDEC</color>
<color name="backgroundLight">#FFFBFCFE</color>
<color name="backgroundDark">#FF191C1E</color>

<color name="grey">#bbbbbb</color>
<color name="light_grey">#F0F0F0</color>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
</resources>
8 changes: 0 additions & 8 deletions androidApp/src/main/res/values/styles_preview.xml

This file was deleted.

11 changes: 3 additions & 8 deletions androidApp/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.AndroidMakers" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@android:color/white</item>
<style name="Theme.AndroidMakers" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowBackground">@color/backgroundLight</item>
</style>

<style name="Theme.AndroidMakers.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/colorPrimary</item>
</style>
</resources>
13 changes: 0 additions & 13 deletions androidApp/src/main/res/values/themes_preview.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class AndroidApplicationPlugin : Plugin<Project> {
apply("org.jetbrains.kotlin.android")
apply("com.google.gms.google-services")
apply("com.google.firebase.crashlytics")
apply("org.jetbrains.kotlin.plugin.serialization")
}

val extension = extensions.getByType<ApplicationExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ class AndroidComposePlugin : Plugin<Project> {

dependencies {
add("implementation", libs.findLibrary("compose.material3").get())
add("implementation", libs.findLibrary("compose.material").get())
add("implementation", libs.findLibrary("compose.material.icons.extended").get())
add("implementation", libs.findLibrary("compose.ui.tooling").get())
add("implementation", libs.findLibrary("navigation.compose").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SigningConfigPlugin : Plugin<Project> {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
"proguard-defaults.txt",
"proguard-rules.pro"
)
if (f.exists()) {
Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.kmp) apply false
alias(libs.plugins.crashlytics) apply false
Expand All @@ -12,5 +11,5 @@ plugins {
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}
Loading

0 comments on commit e940908

Please sign in to comment.