bugsnag/bugsnag-js

[Android] Bugsnag: unable to find ReactNative bundle task 'bundleReleaseJsAndAssets' on react-native 0.71.x+

efstathiosntonas opened this issue · 6 comments

Describe the bug

I'm currently testing 0.72.0-rc.3 but this issue exists on 0.71.x too.

As of react native 0.71 this line on xxx/app/build.gradle is deprecated and totally removed from 0.72:
apply from: "../../node_modules/react-native/react.gradle"

Environment

  • Bugsnag version: 7.20.2
click to see build.gradle
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: "com.facebook.react"

import com.android.build.OutputFile

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
   /* Folders */
   //   The root of your project, i.e. where "package.json" lives. Default is '..'
   // root = file("../")
   //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
   // reactNativeDir = file("../node_modules/react-native")
   //   The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
   // codegenDir = file("../node_modules/react-native-codegen")
   //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
   // cliFile = file("../node_modules/react-native/cli.js")

   /* Variants */
   //   The list of variants to that are debuggable. For those we're going to
   //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
   //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
   // debuggableVariants = ["liteDebug", "prodDebug"]

   /* Bundling */
   //   A list containing the node command and its flags. Default is just 'node'.
   // nodeExecutableAndArgs = ["node"]
   //
   //   The command to run when bundling. By default is 'bundle'
   // bundleCommand = "ram-bundle"
   //
   //   The path to the CLI configuration file. Default is empty.
   // bundleConfig = file(../rn-cli.config.js)
   //
   //   The name of the generated asset file containing your JS bundle
   // bundleAssetName = "MyApplication.android.bundle"
   //
   //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
   // entryFile = file("../js/MyApplication.android.js")
   //
   //   A list of extra flags to pass to the 'bundle' commands.
   //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
   // extraPackagerArgs = []

   /* Hermes Commands */
   //   The hermes compiler command to run. By default it is 'hermesc'
   // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
   //
   //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
   // hermesFlags = ["-O", "-output-source-map"]
}


project.ext.react = [
       enableHermes: true,
       bundleInDebug: true,
       //        bundleInStaging: true,
       //        devDisabledInStaging: true,
       //        hermesFlagsForVariant: {
       //            def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('staging') ? ['-w'] : []
       //        },
       //        deleteDebugFilesForVariant: {
       //            def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('staging')
       //        }
]

project.ext.reanimated = [
       buildFromSource: true
]



/**
* Set this to drawtrue to create two separate APKs instead of one:
*   - An APK that only works on ARM devices
*   - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false

/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US.  Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here.  If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/

/**
* Architectures to build native code for.
*/
def reactNativeArchitectures() {
   def value = project.getProperties().get("reactNativeArchitectures")
   return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}


def safeExtGet(prop, fallback) {
   rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}


def FACEBOOK_SDK_VERSION = safeExtGet('facebookSdkVersion', '13+')

android {
   ndkVersion rootProject.ext.ndkVersion
   compileSdkVersion rootProject.ext.compileSdkVersion
   namespace "com.xxxxxx"

   configurations.all {
       resolutionStrategy {
           force "com.facebook.fresco:fresco:2.5.0"
           force "com.squareup.okhttp3:okhttp:4.10.0"
           force "com.squareup.okhttp3:okhttp-urlconnection:4.10.0"
           force "com.squareup.okio:okio:3.3.0"
       }
   }

   signingConfigs {
       debug {
           keyAlias 'key'
           keyPassword 'xxxxxx'
           storeFile file('../app/debug.keystore')
           storePassword 'xxxxxx'
       }

       signing {
           keyAlias 'key'
           keyPassword 'xxxxx'
           storeFile file('../keystores/release.keystore')
           storePassword 'xxxxxxx'
       }

       staging {
           keyAlias 'key_staging'
           keyPassword 'xxxxxxx'
           storeFile file('../keystores/staging.keystore')
           storePassword 'xxxxx'
           v1SigningEnabled true
           v2SigningEnabled true
       }
   }

   packagingOptions {
       pickFirst '**/armeabi-v7a/libc++_shared.so'
       pickFirst '**/x86/libc++_shared.so'
       pickFirst '**/arm64-v8a/libc++_shared.so'
       pickFirst '**/x86_64/libc++_shared.so'
       pickFirst '**/x86/libjsc.so'
       pickFirst '**/armeabi-v7a/libjsc.so'
   }

   defaultConfig {
       applicationId "com.xxxxx"
       minSdkVersion rootProject.ext.minSdkVersion
       targetSdkVersion rootProject.ext.targetSdkVersion
       versionCode 1140
       versionName "2.0.21"
       multiDexEnabled true
   }

   splits {
       abi {
           reset()
           enable enableSeparateBuildPerCPUArchitecture
           universalApk false // If true, also generate a universal APK
           include( * reactNativeArchitectures())
       }
   }

   buildTypes {
       release {
           minifyEnabled false
           signingConfig signingConfigs.signing
       }

       debug {
           signingConfig signingConfigs.debug
       }
       //        staging {
       //            matchingFallbacks = ['release']
       //            signingConfig signingConfigs.staging
       //            applicationIdSuffix ".stage"
       //        }
   }
   // applicationVariants are e.g. debug, release
   applicationVariants.all {
       variant ->
           variant.outputs.each {
               output ->
                   // For each separate APK per architecture, set a unique version code as described here:
                   // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
                   def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
                   def abi = output.getFilter(OutputFile.ABI)
                   if (abi != null) { // null for the universal-debug, universal-release variants
                       output.versionCodeOverride =
                               defaultConfig.versionCode * 1048576 + versionCodes.get(abi)
                   }
           }
   }

   subprojects {
       project.configurations.all {
           afterEvaluate {
               project ->
                   if (project.hasProperty("android")) {
                       android {
                           compileSdkVersion rootProject.ext.compileSdkVersion
                           buildToolsVersion rootProject.ext.buildToolsVersion
                       }
                   }
           }

           resolutionStrategy.eachDependency {
               details ->
                   if (details.requested.group == 'com.android.support' &&
                           !details.requested.name.contains('multidex')) {
                       details.useVersion rootProject.ext.buildToolsVersion
                   }
           }
       }
   }
}


dependencies {
   dependencies {
       constraints {
           implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
               because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
           }

           implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
               because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
           }
       }
   }

   implementation fileTree(dir: "libs", include: ["*.jar"])
   //noinspection GradleDynamicVersion
   implementation "com.facebook.react:react-native:+" // From node_modules
   implementation "com.facebook.android:facebook-android-sdk:${FACEBOOK_SDK_VERSION}"
   implementation "androidx.core:core-splashscreen:1.0.0"
   implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
   implementation 'androidx.appcompat:appcompat:1.4.2'
   implementation 'com.facebook.fresco:webpsupport:2.5.0'
   implementation 'com.facebook.fresco:fresco:2.5.0'
   implementation 'com.facebook.fresco:animated-webp:2.5.0'
   implementation 'com.facebook.fresco:animated-gif:2.5.0'
   implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
   implementation 'androidx.multidex:multidex:2.0.1'
   implementation 'com.android.support:support-core-utils:24.2.1'
   implementation 'com.google.android.gms:play-services-location:20.0.0'
   implementation "com.bugsnag:bugsnag-plugin-android-okhttp:5.+"
   implementation("com.squareup.okhttp3:okhttp:4.10.0")
   implementation("com.squareup.okhttp3:okhttp-urlconnection:4.10.0")
   implementation("com.squareup.okio:okio:3.3.0")

   debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
       exclude group: 'com.facebook.fbjni'
   }

   debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
       exclude group: 'com.facebook.flipper'
       exclude group: 'com.squareup.okhttp3', module: 'okhttp'
   }

   debugImplementation("com.facebook.flipper:flipper-fresco-plugin:0.182.0") {
       exclude group: 'com.facebook.flipper'
   }

   if (hermesEnabled.toBoolean()) {
       implementation("com.facebook.react:hermes-android")
   } else {
       implementation jscFlavor
   }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
   from configurations.implementation
   into 'libs'
}


project.ext.vectoricons = [
       iconFontNames: [
               'FontAwesome6_Pro_Solid.ttf',
               'FontAwesome6_Pro_Regular.ttf',
       ]
]

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply plugin: "com.bugsnag.android.gradle"
bugsnag {
   uploadReactNativeMappings = true // enables upload of React Native source maps,
   retryCount = 200
   overwrite = true
}
Click to see settings.gradle
rootProject.name = 'xxxxxxxx'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle")
useExpoModules()

ps. Please update the react-native examples on the repo, they're still on 0.6x versions!

Hi @efstathiosntonas - we recently released support for uploading React Native source maps on Android via the bugsnag-cli.

Could you try following our React Native 0.71 specific docs to upload with the bugsnag-cli and let us know how you get on?
https://docs.bugsnag.com/platforms/react-native/react-native/rn071/.

@luke-belton I've followed the docs and now the issue is gone. Thanks for the heads up!

just for clarity, I've removed this no longer needed line: apply from: "../../node_modules/react-native/react.gradle" and it builds fine.

@efstathiosntonas I have removed this line and i still have the same issue

Hi @MaxToyberman

If you are still having issues with this after following our current React Native documentation, would you be able to open a ticket with us directly by contacting support@bugsnag.com?

Please quote this GitHub issue, and include any BugSnag configuration, as well as your build.gradle and settings.gradle files if you can.

Are there any publicly available resolutions to this issue? I get a similar error on React Native Android build:

Bugsnag: unable to find ReactNative bundle task 'bundleMyProdAppReleaseJsAndAssets'
Bugsnag: unable to find ReactNative bundle task 'bundleMyBetaAppReleaseJsAndAssets'

I have two flavors for my Android app: myprodapp and mybetaapp.

So, is this configuration invalid for RN 0.71.x onwards?

bugsnag {
  uploadReactNativeMappings = true
  retryCount = 5
}

And, do I need to use CLI now to upload source map?

Hi @JJSLIoT,

React Native v0.71 introduced some significant changes to the way React Native interacts with Gradle. This means that the BugSnag Android Gradle Plugin is no longer able to automatically upload Android source maps.
The BugSnag CLI has since been improved and is now the recommended tool for uploading React Native source maps.

If you have recently updated your React Native version to 0.71 or higher, you should follow our documentation for manually uploading Android source maps using the BugSnag CLI

The configuration you've mentioned is indeed invalid for React Native 0.71 and above, and we recommend removing the BugSnag Android Gradle Plugin from your application as it will now be incompatible.

If you still want the source maps to be uploaded as part of your build, you can add the command to upload the source maps as a build task after the source map generation.