Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle Upload NDK symbols on every build

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

like image 382
Jesus Dimrix Avatar asked May 13 '20 11:05

Jesus Dimrix


People also ask

How do I include ndk-build projects in Gradle build?

DSL object for per-module ndk-build configurations, such as the path to your Android.mk build script and external native build output directory. To include ndk-build projects in your Gradle build, you need to use Android Studio 2.2 and higher with Android plugin for Gradle 2.2.0 and higher.

How to use NDK debugsymbollevel in Gradle?

To use the option ndk debugSymbolLevel as written in the docs you need an android gradle plugin 4.1 or later. At the time of writing the lastest 4.1 version is 4.1.2 You will need also to install ndk and cmake for android studio. In your android build.gradle you need the to set android gradle plugin version 4.1.2:

How do I find the Android Gradle plugin version?

Find the Android Gradle Plugin version in either of the following locations: 1 File > Project Structure > Project menu in Android Studio 2 The top-level build.gradle file in the project More ...

How to add debugging symbols to the Android app?

There's two places in the app/build.gradle where you can specify bundling of debugging symbols with your app. If you use android.defaultConfig.ndk.debugSymbolLevel it will apply it to all build types (i.e., both debug and release builds).


Video Answer


2 Answers

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.

like image 136
VenomVendor Avatar answered Oct 25 '22 15:10

VenomVendor


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.

like image 2
Martin Zeitler Avatar answered Oct 25 '22 16:10

Martin Zeitler