Android gradle Upload NDK symbols on every build
Asked Answered
B

3

5

I want to upload NDK symbols on every build i do,

Under my Android inside gradle i use to have:

applicationVariants.all { variant ->
    def variantName = variant.name.capitalize()
    println("symbols will be added on varinat ${variantName}")
    def task = project.task("ndkBuild${variantName}")
    task.finalizedBy project.("uploadCrashlyticsSymbolFile${variantName}")
}
  1. this does not compile anymore since i moved to FireBase :

    Could not get unknown property 'uploadCrashlyticsSymbolFile

  2. I don't see this task running.

  3. I basiclly need this task to run on every build:

    ./gradlew app:assembleBUILD_VARIANT\ app:uploadCrashlyticsSymbolFileBUILD_VARIANT

Beka answered 13/5, 2020 at 11:34 Comment(1)
Are you including the buildtype as well? If you look at the list of gradle tasks, that jobs is generated for every flavor and build typeOrthman
T
4

Add this at the bottom of app's build.gradle outside android { ... } block.

afterEvaluate {
    android.applicationVariants.all { variant ->
        def variantName = variant.name.capitalize()
        println("symbols will be added on variant ${variantName}")

        def task = tasks.findByName("assemble${variantName}")
        def uploader = "uploadCrashlyticsSymbolFile${variantName}"

        // This triggers after task completion
        task?.finalizedBy(uploader)

        // This ensures ordering
        task?.mustRunAfter(uploader)
    }
}

You can try without afterEvaluate block. It should still work.

Telethermometer answered 27/5, 2020 at 21:42 Comment(0)
M
2

Likely you'd need to use Firebase App Distribution, which permits automatic upload of release build artifacts - and if you have the artifact with the matching debug symbols, they could actually be used - without the matching assembly, the symbols are somewhat irrelevant.

Number 1 is obviously a wrongful assumption, because the documentation clearly states:

./gradlew app:assembleBUILD_VARIANT app:uploadCrashlyticsSymbolFileBUILD_VARIANT

And this is already answered here.


In order to always upload, one can create a task dependency:

assembleRelease.finalizedBy uploadCrashlyticsSymbolFileRelease

This may require setting unstrippedNativeLibsDir and strippedNativeLibsDir.

Mocha answered 23/5, 2020 at 8:56 Comment(0)
C
0

Here's what I use to get symbols uploaded on every build. It works with both APK and App Bundle (AAB) builds and uses Gradle Task providers to avoid early configurations of Gradle tasks, so should be also more optimized compared to the more simplistic version provided by VenomVendor. It should automatically handle all application variants but silently ignores ones where required tasks are missing - for example, if symbols uploading option which actually just enables task generation (nativeSymbolUploadEnabled) is not set.

Don't know why Google cannot make this automatic - maybe they don't want to have their servers flooded with non-final builds.

afterEvaluate {
// Automatic NDK symbols uploading.
android.applicationVariants.configureEach { variant ->
    final def variantName = variant.name.capitalize()

    final def assembleTaskProvider = variant.assembleProvider
    final def uploadCrashlyticsSymbolFileTaskName = "uploadCrashlyticsSymbolFile${variantName}"
    final def bundleTaskName = "bundle${variantName}"

    try
    {
        final def uploadCrashlyticsSymbolFileTaskProvider = project.tasks.named(uploadCrashlyticsSymbolFileTaskName)
        if (uploadCrashlyticsSymbolFileTaskProvider != null)
        {
            // 'assemble***' task is used when building APK.
            if (assembleTaskProvider != null)
            {
                assembleTaskProvider.configure { assembleTask ->
                    // This triggers after task completion
                    assembleTask.finalizedBy(uploadCrashlyticsSymbolFileTaskProvider)
                }

                uploadCrashlyticsSymbolFileTaskProvider.configure { uploadCrashlyticsSymbolFileTask ->
                    // This ensures ordering
                    uploadCrashlyticsSymbolFileTask.mustRunAfter(assembleTaskProvider)
                }
            }

            // 'bundle***' task is used when building App Bundle (AAB).
            try
            {
                final def bundleTaskProvider = project.tasks.named(bundleTaskName)
                if (bundleTaskProvider != null)
                {
                    bundleTaskProvider.configure { bundleTask ->
                        // This triggers after task completion
                        bundleTask.finalizedBy(uploadCrashlyticsSymbolFileTaskProvider)
                    }

                    uploadCrashlyticsSymbolFileTaskProvider.configure { uploadCrashlyticsSymbolFileTask ->
                        // This ensures ordering
                        uploadCrashlyticsSymbolFileTask.mustRunAfter(bundleTaskProvider)
                    }
                }
            }
            catch (ignored) // Ignore all possible throws from 'named()' API.
            { }
        }
    }
    catch (ignored) // Ignore all possible throws from 'named()' API.
    { }
}

}

Cur answered 9/4, 2024 at 12:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.