Suggested build files changes #177

Closed
opened 2025-09-18 18:13:35 +03:00 by MateusRodCosta · 0 comments
MateusRodCosta commented 2025-09-18 18:13:35 +03:00 (Migrated from github.com)

Hello, I have recently looked a bit on Phocid build files and I think there are a few improvements that can be done.

gradle.properties changes

jvmargs

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

This defines the parameters given to the Java process that runs Gradle.

I personally have standardized my projects to something like this (I have 32 GB of RAM, so I gave it quite a bit of RAM):

org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.daemon.jvm.options="-Xmx4G"

The relevant part is the 4GB for both Java a and the Kotlin daemon.

gradle speedup

To speed up the gradle build I also use these:

org.gradle.caching=true
org.gradle.parallel=true

Those can generally be applied to any Gradle project without any drawbacks and they are well documented on the Gradle website:

There's a third option however it causes a few issues with you project:

org.gradle.configuration-cache=true

Apparently this one is not a fan of some of your custom tasks

others

This one can be removed:

android.nonTransitiveRClass=true

Since AGP 8.0 it's set to true by default.

result

If you apply those changes you should get a file similar to this:

org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.daemon.jvm.options="-Xmx4G"
org.gradle.caching=true
org.gradle.parallel=true
kotlin.code.style=official
android.useAndroidX=true

Module-level buiild.gradle

Update Java

These are set to Java 8:

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions { jvmTarget = "1.8" }

AFAIK sourceCompatibility determines the features that can be used in Java code based on which release the feature was introduced, targetCompatibility and kotlinOptions.jvmTarget affect the Java and Kotlin bytecode generation (whcih later goes through a process to become dalvik bytecode).

Ideally this should be updated to a newer Java LTS, such as 11, 17, 21 or 25. According to the Android developer docs
, Android uses Java 11 since Android 12 and Java 17 since Android 14 (but since ART is a Mainline module since Android 12, this means Java 17 support was backported)

Compose compiler

This line is uneeded:

composeOptions { kotlinCompilerExtensionVersion = "1.5.1" }

According to the docs you are already using its replacement:

compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
Hello, I have recently looked a bit on Phocid build files and I think there are a few improvements that can be done. ## gradle.properties changes ### jvmargs ``` org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 ``` This defines the parameters given to the Java process that runs Gradle. I personally have standardized my projects to something like this (I have 32 GB of RAM, so I gave it quite a bit of RAM): ``` org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.daemon.jvm.options="-Xmx4G" ``` The relevant part is the 4GB for both Java a and the Kotlin daemon. ### gradle speedup To speed up the gradle build I also use these: ``` org.gradle.caching=true org.gradle.parallel=true ``` Those can generally be applied to any Gradle project without any drawbacks and [they are well documented on the Gradle website](https://docs.gradle.org/current/userguide/performance.html): There's a third option however it causes a few issues with you project: ``` org.gradle.configuration-cache=true ``` Apparently this one is not a fan of some of your custom tasks ### others This one can be removed: ``` android.nonTransitiveRClass=true ``` [Since AGP 8.0 it's set to true by default](https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes#default-changes). ### result If you apply those changes you should get a file similar to this: ``` org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.daemon.jvm.options="-Xmx4G" org.gradle.caching=true org.gradle.parallel=true kotlin.code.style=official android.useAndroidX=true ``` ## Module-level buiild.gradle ### Update Java These are set to Java 8: ``` compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = "1.8" } ``` AFAIK `sourceCompatibility` determines the features that can be used in Java code based on which release the feature was introduced, `targetCompatibility` and `kotlinOptions.jvmTarget` affect the Java and Kotlin bytecode generation (whcih later goes through a process to become dalvik bytecode). Ideally this should be updated to a newer Java LTS, such as 11, 17, 21 or 25. [According to the Android developer docs ](https://developer.android.com/build/jdks), Android uses Java 11 since Android 12 and Java 17 since Android 14 (but since ART is a Mainline module since Android 12, this means Java 17 support was backported) ### Compose compiler This line is uneeded: ``` composeOptions { kotlinCompilerExtensionVersion = "1.5.1" } ``` [According to the docs](https://developer.android.com/jetpack/androidx/releases/compose-kotlin) you are already using its replacement: ``` compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
novvux/Blissid#177
No description provided.