diff --git a/CHANGELOG.md b/CHANGELOG.md index ea91f4ed3..e99c48290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ Changelog **Unreleased** -------------- +0.23.2 +------ + +_2024-12-11_ + +- Add `foundry.android.test.targetApkArch` property to specify a target architecture for androidTest APKs. This allows us to exclude jni libs from unmatched architectures to shrink APK size. + 0.23.1 ------ diff --git a/gradle.properties b/gradle.properties index a491cc624..624814a00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -52,4 +52,4 @@ POM_DEVELOPER_ID=slackhq POM_DEVELOPER_NAME=Slack Technologies, Inc. POM_DEVELOPER_URL=https://github.com/slackhq POM_INCEPTION_YEAR=2022 -VERSION_NAME=1.0.0-SNAPSHOT +VERSION_NAME=0.23.2 diff --git a/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/FoundryProperties.kt b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/FoundryProperties.kt index e67349e35..34ae584d5 100644 --- a/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/FoundryProperties.kt +++ b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/FoundryProperties.kt @@ -16,6 +16,7 @@ package foundry.gradle import foundry.common.FoundryKeys +import foundry.gradle.android.AndroidArchitecture import foundry.gradle.anvil.AnvilMode import foundry.gradle.artifacts.FoundryArtifact import foundry.gradle.properties.PropertyResolver @@ -496,6 +497,17 @@ internal constructor( public val compressAndroidTestApksWithLegacyPackaging: Provider get() = resolver.booleanProvider("foundry.android.test.compressWithLegacyPackaging", false) + /** + * Option to specify which architecture to target for androidTest APKs. These are universal by + * default, which can be quite bloated. This allows for targeting a subset of arches by excluding + * jni libs from other ones. + */ + public val targetAndroidTestApksArch: Provider + get() = + resolver.optionalStringProvider("foundry.android.test.targetApkArch").map { + AndroidArchitecture.valueOf(it) + } + /** Flag for minifying androidTest APks with R8. This just tree shakes. */ public val minifyAndroidTestApks: Provider get() = resolver.booleanProvider("foundry.android.test.minifyEnabled", false) diff --git a/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/StandardProjectConfigurations.kt b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/StandardProjectConfigurations.kt index 9c85a31a8..895a66903 100644 --- a/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/StandardProjectConfigurations.kt +++ b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/StandardProjectConfigurations.kt @@ -34,6 +34,7 @@ import com.android.build.gradle.tasks.JavaPreCompileTask import com.autonomousapps.DependencyAnalysisSubExtension import com.bugsnag.android.gradle.BugsnagPluginExtension import foundry.gradle.Configurations.isPlatformConfigurationName +import foundry.gradle.android.AndroidArchitecture import foundry.gradle.artifacts.FoundryArtifact import foundry.gradle.artifacts.Publisher import foundry.gradle.dependencies.FoundryDependencies @@ -523,6 +524,14 @@ internal class StandardProjectConfigurations( packaging.jniLibs.useLegacyPackagingFromBundle.set( foundryProperties.compressAndroidTestApksWithLegacyPackaging ) + foundryProperties.targetAndroidTestApksArch.orNull?.let { targetArch -> + packaging.jniLibs.excludes.addAll( + // Exclude out non-targeted architectures + AndroidArchitecture.entries + .filterNot { it == targetArch } + .map { "**/${it.jniLibsPath}/*.so" } + ) + } } } if (foundryProperties.enableEmulatorWtfForAndroidTest) { diff --git a/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/android/AndroidArchitecture.kt b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/android/AndroidArchitecture.kt new file mode 100644 index 000000000..ba5f13c51 --- /dev/null +++ b/platforms/gradle/foundry-gradle-plugin/src/main/kotlin/foundry/gradle/android/AndroidArchitecture.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 Slack Technologies, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package foundry.gradle.android + +/** Represents possible Android architectures. */ +public enum class AndroidArchitecture(public val jniLibsPath: String) { + ARM64_V8A("arm64-v8a"), + ARMEABI_V7A("armeabi-v7a"), + X86("x86"), + X86_64("x86_64"), +}