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

Optimize and fix android dependencies #299

Merged
merged 20 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d0daff1
upgrade libraries and remove unused ones
cbeyls Apr 25, 2024
a74275a
- remove AppCompat and Material Components.
cbeyls Apr 25, 2024
94fe595
- remove Firebase in-app messaging which depends on Glide an AppCompat
cbeyls Apr 25, 2024
7ba8a1a
remove unused Coil image loader
cbeyls Apr 25, 2024
eeca7f8
remove transitive dependencies to AppCompat for Precompose, Moko and …
cbeyls Apr 25, 2024
cff1bc7
add missing core library desugaring for the Android app (to properly …
cbeyls Apr 25, 2024
8941b06
replace default Proguard rules with more optimized ones (enabling R8 …
cbeyls Apr 25, 2024
8535380
disable Kotlin assertions for release builds and remove unnecessary p…
cbeyls Apr 25, 2024
42a098c
disable Android DI debug logging from release builds
cbeyls Apr 25, 2024
4e1d205
remove AppCompat version
cbeyls Apr 25, 2024
5d2e9b1
remove unused compose-material library (only compose-material3 is used)
cbeyls Apr 25, 2024
918f084
remove unused Kotlin Serialization plugin
cbeyls Apr 25, 2024
14293d9
align all compose versions together to ensure the best compatibility …
cbeyls Apr 25, 2024
6ff9939
remove unused navigation-compose library from the Android app
cbeyls Apr 25, 2024
88b55c8
fix Compose dependencies of the Wear app
cbeyls Apr 25, 2024
f41773c
fix Apollo version and downgrade to 4.0.0-beta.2 which doesn't depend…
cbeyls Apr 25, 2024
b80f549
disable support vector drawables for Wear because minSDK is >24
cbeyls Apr 27, 2024
5ac1bb5
add missing Proguard defaults for Wear
cbeyls Apr 27, 2024
ddf6efc
exclude unused packaged files an jni libs, and update compiler argume…
cbeyls Apr 27, 2024
d2e6c8b
switch to horologist 0.5.25 which is the version designed for Wear Co…
cbeyls Apr 27, 2024
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
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"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use proguard-android-optimized here to benefit from default rules with all possible optimizations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rules are better but still way too conservative in my opinion, and they haven't been updated for ages. I can give you a detailed explanation later.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware that they are outdated. My thought was it might be still safer for a small project.

I totally agree that adding rules based on your project is better.

"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
Loading