From 7476ce071280a67f5888db7104e68ec8205b0ba3 Mon Sep 17 00:00:00 2001 From: Philipp Hasper Date: Wed, 23 Sep 2026 14:39:15 +0200 Subject: [PATCH 1/2] feat(build): First step towards R8 minify - still crashing With keeping the apache httpclient, webdav and ical4j, the app at least starts. But it crashes when clicking the plus button (OCFileListBottomSheetDialog). Related to #17640 Assisted-by: GithubCopilot:GPT-5.4 Signed-off-by: Philipp Hasper --- app/build.gradle.kts | 7 ++++++- app/proguard-rules.pro | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/proguard-rules.pro diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9db2148e375c..3a18842ec845 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -142,9 +142,14 @@ android { buildTypes { release { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) buildConfigField("String", "NC_TEST_SERVER_DATA_STRING", "\"\"") } - debug { enableUnitTestCoverage = project.hasProperty("coverage") enableAndroidTestCoverage = project.hasProperty("coverage") diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000000..3817ac49aca7 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,24 @@ +# Nextcloud - Android Client +# +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. + +# Silence missing-class warnings from optional transitive dependencies and Android/JDK API gaps. +-dontwarn com.gemalto.jp2.JP2Decoder +-dontwarn com.gemalto.jp2.JP2Encoder +-dontwarn java.time.zone.ZoneRulesProvider +-dontwarn org.joda.convert.ToString + +# Commons HttpClient is still used at runtime, so keep these packages from being stripped or renamed. +-keep class org.apache.commons.httpclient.* { *; } +-keep class org.apache.commons.httpclient.auth.** { *; } + +# Some libraries load .properties resources relative to their package. +# Keeping the package names preserves Class.getResourceAsStream(...) lookups after shrinking. +-keeppackagenames org.apache.jackrabbit.webdav +-keeppackagenames net.fortuna.ical4j +-keep class org.apache.commons.httpclient.cookie.** { *; } From 185f57eec38908d5b569ef2b5adf1c9a2c30091d Mon Sep 17 00:00:00 2001 From: Philipp Hasper Date: Wed, 23 Sep 2026 16:09:50 +0200 Subject: [PATCH 2/2] feat(build): gradle property to control optimization, set for CI This adds a property to enable the optimization, and it is activated for the CI - build - screenshot tests - instrumentation tests - unit test (though probably without effect) For this to work, it must also be present in the debug build variant Signed-off-by: Philipp Hasper --- .github/workflows/assembleFlavors.yml | 3 +-- .github/workflows/unit-tests.yml | 2 +- app/build.gradle.kts | 12 +++++++++--- scripts/runAllScreenshotCombinations | 2 ++ scripts/runCombinedTest.sh | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/assembleFlavors.yml b/.github/workflows/assembleFlavors.yml index 587b27b0d698..057d02649ec0 100644 --- a/.github/workflows/assembleFlavors.yml +++ b/.github/workflows/assembleFlavors.yml @@ -47,5 +47,4 @@ jobs: echo "kotlin.daemon.jvmargs=-Xmx3g -XX:+UseParallelGC -XX:MaxMetaspaceSize=512m" echo "org.gradle.workers.max=2" } >> gradle.properties - ./gradlew ${{ matrix.tasks }} - + ./gradlew ${{ matrix.tasks }} -Pminify diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 7386a4ad003d..48ae0657ca27 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -40,7 +40,7 @@ jobs: uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0 - name: Run unit tests with coverage - run: ./gradlew jacocoTestGplayDebugUnitTest + run: ./gradlew jacocoTestGplayDebugUnitTest -Pminify - name: Upload failing results if: ${{ failure() }} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3a18842ec845..0080cc34ae9b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,6 +20,8 @@ val shotTest = System.getenv("SHOT_TEST") == "true" val ciBuild = System.getenv("CI") == "true" val perfAnalysis = project.hasProperty("perfAnalysis") +val minify = project.hasProperty("minify") // shall be off by default + plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.compose) @@ -141,16 +143,20 @@ android { flavorDimensions += "default" buildTypes { - release { - isMinifyEnabled = true - isShrinkResources = true + fun com.android.build.api.dsl.BuildType.commonMinifyConfig() { + isMinifyEnabled = minify + isShrinkResources = minify proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + } + release { + commonMinifyConfig() buildConfigField("String", "NC_TEST_SERVER_DATA_STRING", "\"\"") } debug { + commonMinifyConfig() enableUnitTestCoverage = project.hasProperty("coverage") enableAndroidTestCoverage = project.hasProperty("coverage") resConfigs("xxxhdpi") diff --git a/scripts/runAllScreenshotCombinations b/scripts/runAllScreenshotCombinations index 6e208d20eed0..a0d7caf99950 100755 --- a/scripts/runAllScreenshotCombinations +++ b/scripts/runAllScreenshotCombinations @@ -30,6 +30,7 @@ do if [[ $1 = "noCI" ]]; then ./gradlew --console plain genericDebugExecuteScreenshotTests \ $record \ + -Pminify \ -Pscreenshot=true \ -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \ -Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \ @@ -43,6 +44,7 @@ do else ./gradlew --console plain genericDebugExecuteScreenshotTests \ $record \ + -Pminify \ -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \ -Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \ -Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" /dev/null \ diff --git a/scripts/runCombinedTest.sh b/scripts/runCombinedTest.sh index 86ecf0cc6763..29c12989b0a6 100755 --- a/scripts/runCombinedTest.sh +++ b/scripts/runCombinedTest.sh @@ -24,12 +24,13 @@ scripts/deleteOldComments.sh "$BRANCH" "IT" "$DRONE_PULL_REQUEST" scripts/wait_for_emulator.sh || exit 1 -./gradlew installGplayDebugAndroidTest +./gradlew installGplayDebugAndroidTest -Pminify gradle_arguments=( -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest -Pandroid.testInstrumentationRunnerArguments.filter=com.nextcloud.test.FlakyTestFilter,com.nextcloud.test.ServerVersionFilter + -Pminify ) if [[ "$BRANCH" =~ ^stable([0-9]+)$ ]]; then