Open venator85 opened 2 years ago
While we wait for a proper fix, here are some workarounds:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.guardsquare.proguard'
android { buildTypes { debug { minifyEnabled false } release { minifyEnabled false firebaseCrashlytics { mappingFileUploadEnabled true } } } }
proguard { configurations { release { defaultConfiguration 'proguard-android-optimize.txt' configuration 'proguard-rules.pro' } } }
project.afterEvaluate { // Iterate over all variants for which obfuscation is enabled. Note this example // only checks the flag set in the buildType, not defaultConfig or product flavors. def variants = project.android.applicationVariants.findAll { it.buildType.extensions.firebaseCrashlytics.mappingFileUploadEnabled } variants.each { variant -> def uploadTaskName = "uploadCrashlyticsMappingFile${variant.name.capitalize()}" TaskProvider uploadCrashlyticsMappingFileTask try { uploadCrashlyticsMappingFileTask = tasks.named(uploadTaskName) } catch (UnknownTaskException e) { throw new GradleException("${uploadTaskName} does not exist for variant ${variant.name}. " + "Make sure the Crashlytics plugin has been applied and " + "firebaseCrashlytics.mappingFileUploadEnabled is set to true.", e) }
uploadCrashlyticsMappingFileTask.configure { t ->
t.mappingFileProvider = project.objects.property(FileCollection.class)
t.mappingFileProvider.value(project.files(file("${project.buildDir}/outputs/proguard/${variant.name}/mapping/mapping.txt")))
dependsOn "transformClassesAndResourcesWithProguardTransformFor${variant.name.capitalize()}"
}
// Manually set a dependency on the upload task for whatever the parent
// build task is (assemble, bundle, etc). If this is not set,
// uploadCrashlyticsMappingFileRelease will need to be explicitly invoked
tasks.findByName("assemble${variant.name.capitalize()}").configure {
dependsOn uploadCrashlyticsMappingFileTask
}
}
}
I have the same issue, and this solved the missing proguard map in a bundle file. Note that it's hardcoded on release and no flavors. It's a bit hacky, but not too much. And since this runs before signing the bundle, there are no issues uploading it to Google Play.
In your app build.gradle: (not the toplevel one):
task addProguardMappingToReleaseIntermediateBundle(type: Zip) {
description = "Add proguard mapping to bundle file for Google Play upload"
archiveName = "intermediary-bundle.tmp.aab"
destinationDirectory = file("${project.buildDir}/intermediates/intermediary_bundle/release/")
from {
zipTree("${project.buildDir}/intermediates/intermediary_bundle/release/intermediary-bundle.aab")
}
into("BUNDLE-METADATA/com.android.tools.build.obfuscation") {
from {
file("${project.buildDir}/outputs/proguard/release/mapping/mapping.txt")
}
}
rename { file ->
if (file == "mapping.txt") {
return "proguard.map"
} else {
return null
}
}
doLast {
var source = "${project.buildDir}/intermediates/intermediary_bundle/release/intermediary-bundle.tmp.aab"
var target = source.replace(".tmp.aab", ".aab")
file(target).delete()
file(source).renameTo(file(target))
}
}
project.afterEvaluate
{
packageReleaseBundle.finalizedBy(addProguardMappingToReleaseIntermediateBundle)
}
Hi, I have integrated the latest version 7.2.2 of Proguard in my app, replacing R8. I'm using the Android Gradle Plugin version 7.2.2. I have followed exactly the instructions in the Quick Start - ProGuard Gradle Plugin section.
When I produce an AAB, running for example
./gradlew bundleRelease
:This is a serious issue especially for Crashlytics, since it doesn't support manual upload of the mapping file (unlike Google Play Console where this is possible).
I think all of these issues originate from the fact that the mappingFile is not correctly 'injected' in the resolved application variant, so the Android Gradle Plugin doesn't include it in the AAB:
The issue can be easily reproduced by using the sample app under
examples/android-plugin
. If you run./gradlew bundleRelease
, the produced AAB file at pathbuild/outputs/bundle/release/android-plugin-release.aab
doesn't include theBUNDLE-METADATA/com.android.tools.build.obfuscation
directory.Is there any way to workaround this issue? Is a proper fix in development? Thanks