[#707] Exclude files from release packaging only

These files are used by Android Studio in debug builds to discover the version of Compose being used by an app.  They should be preserved for debug builds but can be stripped from release builds.

Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
Carter Jernigan 2023-01-18 11:25:06 -05:00 committed by GitHub
parent da0e909458
commit e8a478cf33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 33 deletions

View File

@ -1,3 +1,5 @@
import java.util.Locale
plugins {
id("com.android.application")
kotlin("android")
@ -139,32 +141,6 @@ android {
}
}
packagingOptions {
resources.excludes.addAll(
listOf(
"**/*.kotlin_metadata",
".readme",
"build-data.properties",
"META-INF/*.kotlin_module",
"META-INF/android.arch**",
"META-INF/androidx**",
"META-INF/com.android**",
"META-INF/com.google.android.material_material.version",
"META-INF/com.google.dagger_dagger.version",
"META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor",
"META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar",
"META-INF/services/org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages\$Extension",
"firebase-**.properties",
"kotlin/**",
"play-services-**.properties",
"protolite-well-known-types.properties",
"transport-api.properties",
"transport-backend-cct.properties",
"transport-runtime.properties"
)
)
}
playConfigs {
register(testNetFlavorName) {
enabled.set(false)
@ -210,15 +186,19 @@ dependencies {
}
val googlePlayServiceKeyFilePath = project.property("ZCASH_GOOGLE_PLAY_SERVICE_KEY_FILE_PATH").toString()
if (googlePlayServiceKeyFilePath.isNotEmpty()) {
// Update the versionName to reflect bumps in versionCode
androidComponents {
val versionCodeOffset = 0 // Change this to zero the final digit of the versionName
onVariants { variant ->
for (output in variant.outputs) {
androidComponents {
onVariants { variant ->
for (output in variant.outputs) {
if (googlePlayServiceKeyFilePath.isNotEmpty()) {
// Update the versionName to reflect bumps in versionCode
val versionCodeOffset = 0 // Change this to zero the final digit of the versionName
val processedVersionCode = output.versionCode.map { playVersionCode ->
val defaultVersionName = project.property("ZCASH_VERSION_NAME").toString()
// Version names will look like `myCustomVersionName.123`
@Suppress("UNNECESSARY_SAFE_CALL")
playVersionCode?.let {
val delta = it - versionCodeOffset
if (delta < 0) {
@ -232,8 +212,38 @@ if (googlePlayServiceKeyFilePath.isNotEmpty()) {
output.versionName.set(processedVersionCode)
}
}
}
variant.packaging.resources.excludes.addAll(listOf(
".readme",
))
if (variant.name.toLowerCase(Locale.US).contains("release")) {
variant.packaging.resources.excludes.addAll(listOf(
"**/*.kotlin_metadata",
"DebugProbesKt.bin",
"META-INF/*.kotlin_module",
"META-INF/*.version",
"META-INF/android.arch**",
"META-INF/androidx**",
"META-INF/com.android**",
"META-INF/com.google.android.material_material.version",
"META-INF/com.google.dagger_dagger.version",
"build-data.properties",
"core.properties",
"firebase-**.properties",
"kotlin-tooling-metadata.json",
"kotlin/**",
"play-services-**.properties",
"protolite-well-known-types.properties",
"transport-api.properties",
"transport-backend-cct.properties",
"transport-runtime.properties"
))
}
}
}
if (googlePlayServiceKeyFilePath.isNotEmpty()) {
configure<com.github.triplet.gradle.play.PlayPublisherExtension> {
serviceAccountCredentials.set(File(googlePlayServiceKeyFilePath))

View File

@ -0,0 +1,39 @@
* Debug APK contents — Androidx libraries include extra text files that Android Studio reads during debugging. We need to make sure these files are preserved for debug builds.
1. Create a debug build of the app, e.g. `./gradlew :app:assembleDebug`
1. View the APK in Android Studio
1. Build menu
1. Analyze APK
1. Open the APK that was built in the first step above
1. Verify the APK contains various debug properties and versions files in the root directory and under META-INF/
* Release APK contents
1. Create a debug build of the app, e.g. `./gradlew :app:assembleRelease`
1. View the APK in Android Studio
1. Build menu
1. Analyze APK
1. Open the APK that was built in the first step above
1. Verify the APK contains various debug properties
* Verify the unzipped directory contains the following:
* AndroidManifest.xml
* assets/
* classes.dex (and perhaps additional classesN.dex)
* compact_formats.proto
* darkside.proto
* google/
* lib/
* META-INF/ (which should only contain a few files)
* res/
* resources.arsc
* service.proto
* Sanity check release app
1. Open `gradle.properties` file and ensure that you have the `IS_SIGN_RELEASE_BUILD_WITH_DEBUG_KEY` property set to true. Don't forget to switch the property back to false after this test, so any of your subsequent tests are not affected by it.
1. Create a release build of the app, e.g. `./gradlew :app:bundleRelease :app:packageZcashmainnetReleaseUniversalApk`. Note these Gradle tasks will create an app bundle, then derive the APK from the app bundle. This more closely matches how the app would be distributed to users through Google Play.
1. Connect an Android device with developer mode enabled to your computer
1. On a computer with the Android developer tools, run `adb logcat`
1. Install the app on the device, e.g. `adb install -r $pathToUniversalApk`
1. Run the app
1. Verify
1. The app launches successfully
1. Minimal logs from the app are printed to logcat. Android itself may print logs, but our release build should have logging stripped out
1. The app is using mainnet