I have a React Native application and I'm trying to specify the folder for storing the generated source map in project.ext.react like so (I need it to implement a library which will help me debug JS errors)
project.ext.react = [
...
extraPackagerArgs : [ "--sourcemap-output", "$buildDir/intermediates/assets/$buildType/index.android.bundle.map" ]
]
As evident, the path should be something like <buildDir>/intermediates/assets/<buildType>/index.android.bundle.map
(e.g.
<buildDir>/intermediates/assets/release/index.android.bundle.map in case of release and <buildDir>/intermediates/assets/debug/index.android.bundle.map in case of debug)
After referring to several answers on StackOverflow and outside, I'm getting the buildType in the build.gradle by declaring it first and then assigning it:
//3rd line of build.gradle
def buildType
....
//much later
applicationVariants.all { variant ->
buildType = variant.buildType.name
....
However, this leads to a problem where buildType is initialized much after it is used, and so the output path becomes something like <buildDir>/intermediates/assets/null/index.android.bundle.map, thereby failing the whole process for me. Is there a way to get the build type earlier on?
I finally found a way (though its not a very clean one) to look through the array of gradle tasks:
def buildType = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")}?"debug":"release"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With