Instabug/Instabug-React-Native

Android build fail when if productFlavors configurated

retyui opened this issue ยท 12 comments

Steps to Reproduce the Problem

Add productFlavors prod & staging

try to clean build/assemble apk

./android/gradlew clear -p android

it will fail Cannot invoke method finalizedBy() on null object

more details:

// instabug-reactnative/android/sourcemaps.gradle

    def bundleTask = appProject.tasks.find {
        task -> task.name.endsWithIgnoreCase('bundleReleaseJsAndAssets')
    }

   bundleTask // null - 
   // ^^^ because when android has flavors task will be called:
   // - bundleProdReleaseJsAndAssets
   // - bundleStagingReleaseJsAndAssets

    bundleTask.finalizedBy uploadSourcemaps

Expected Behavior

no errors

Actual Behavior

FAILURE: Build failed with an exception.

* Where:
Script 'node_modules/instabug-reactnative/android/sourcemaps.gradle' line: 11

* What went wrong:
Cannot invoke method finalizedBy() on null object

Instabug integration code

no

SDK Version

the latest

React Native, iOS and Android Versions

android

Device Model

[Optional] Project That Reproduces the Issue

Hi @retyui! Thanks for reporting this issue and providing a very helpful description of the problem. We have been able to reproduce the issue from our side and created a PR with the fix (#975) and a snapshot that you can install using the command below:

npm install https://github.com/Instabug/Instabug-React-Native\#snapshot/11.10.0-MOB-12305

it doesn't work

  1. uploadSourcemaps assigned only for first task ReleaseJsAndAssets and never invoked
    because assigned to bundleProdReleaseJsAndAssets
    but I built staging bundleStagingReleaseJsAndAssets

  2. also sourceMapDest is incorrect:

def sourceMapDest = 'build/generated/sourcemaps/react/release/index.android.bundle.map'
                  // build/generated/sourcemaps/react/staging/release/index.android.bundle.map

@retyui Thanks again for testing it and letting us know that it's still failing. We created another PR with a possible fix for these problems (#978) and will update you with a snapshot once ready.

@retyui Your snapshot is ready, you can install it using the same command as before:

npm install https://github.com/Instabug/Instabug-React-Native\#snapshot/11.10.0-MOB-12305

Please test it and let us know if it fixes your issue so we can proceed with merging it or investigating it further.

@a7medev did you tested it?

For me it fails:

> Task :app:bundleStagingReleaseJsAndAssets
info Writing bundle output to:, /Users/i/all_work/sp/src/react/packages/obt/mobile/android/app/build/generated/assets/react/staging/release/index.android.bundle
info Writing sourcemap output to:, /Users/i/all_work/sp/src/react/packages/obt/mobile/android/app/build/intermediates/sourcemaps/react/staging/release/index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 38 asset files
info Done copying assets

> Task :instabug-reactnative:uploadSourcemapsStaging
Failed to upload source map file.
Reason: Unable to find source map file at: /Users/i/all_work/sp/src/react/packages/obt/mobile/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map

@retyui Sorry for the inconvenience. It was due to a slight change I introduced after testing it. I did fix it now and it should work fine if you reinstall it with the same command. Please let us know if there are any further issues.

Now seems it's works !

but fail with the same error that I reported in another issue: #976

> Task :instabug-reactnative:uploadSourcemapsStaging
Environment variable `INSTABUG_APP_TOKEN` might have incorrect value, make sure this was intentional:
   Environment Value: 1234
   Default Value: null
npx: installed 53 in 5.354s
command not found: instabug
Failed to upload source map file.
Reason: Process 'command 'npx'' finished with non-zero exit value 1

Can you use the same why how it was done on iOS? (instead of npx )

https://github.com/Instabug/Instabug-React-Native/blob/a9c47e26c6eb6d9b0246c211c837a0ec7e77b46d/ios/sourcemaps.sh#LL32C1-L37C27

node $instabug_dir/bin/index.js upload-sourcemaps

see: #978

stale commented

This issue has been automatically marked as pending feedback because we need additional information to be able to investigate it further. It will be closed in 7 days if it remains inactive. Thank you for your contributions.

@retyui This issue is now fixed in v11.12.0, please update to the latest version instead of using the snapshot ๐Ÿ™๐Ÿผ

Hi there, that's great when Instabug supports flavors for Android. But in my React Native app, the source map is generated on a little bit different folder.
build/generated/sourcemaps/react/stagingRelease/index.android.bundle.map instead of staging/release.
So the fix still failed to upload the source map.
Anyone know the reason and how can we fix that? Thanks in advance!

@a7medev
And I also got an issue with the INSTABUG_APP_TOKEN, I set up Instabug for multiple envs so I move the key to the .env files and load it using react-native-config. And when uploading source map, it can not found the INSTABUG_APP_TOKEN in the JS code via find-token.sh.
Is there any way to set INSTABUG_APP_TOKEN as env variable when running sourcemaps.gradle.
Thanks!