bugsnag / bugsnag-js

JavaScript error handling tool for BugSnag. Monitor and report JavaScript bugs & errors.
https://docs.bugsnag.com/platforms/javascript
MIT License
838 stars 252 forks source link

App getting crashed for Android release builds because of bugsnag integration. React native app #2162

Open vksgautam1986 opened 1 week ago

vksgautam1986 commented 1 week ago

if i remove bugsnag , it works fine for android. for ios its working fine with bugsnag for release build RN 0.73.8 Bugsnag -- latest those crashes for android did not come in bugsnag portal also.

Package json

{ "name": "appname", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint .", "all": "npm i --f && cd ios && pod deintegrate && pod install && cd ..", "clean": "cd android && ./gradlew clean && cd ..", "debug-build": "react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res && cd android && ./gradlew assembleDebug && cd ..", "release-build": "react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res && rm -rf android/app/src/main/res/drawable- && rm -rf android/app/src/main/res/raw/ && cd android && ./gradlew assembleRelease && cd ..", "postinstall": "patch-package", "bugsnag:create-build": "bugsnag-cli create-build", "bugsnag:upload-android-ndk": "bugsnag-cli upload android-ndk android/", "bugsnag:upload-android-proguard": "bugsnag-cli upload android-proguard android/", "bugsnag:upload-rn-android": "bugsnag-cli upload react-native-android", "bugsnag:upload-dsym": "bugsnag-cli upload dsym ios/", "bugsnag:upload-rn-ios": "bugsnag-cli upload react-native-ios", "bugsnag:upload": "bugsnag-cli upload android-ndk android/ && bugsnag-cli upload android-proguard android/ && bugsnag-cli upload react-native-android && bugsnag-cli upload dsym ios/ && bugsnag-cli upload react-native-ios" }, "dependencies": { "@bugsnag/react-native": "latest", "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-community/datetimepicker": "^8.1.0", "@react-native-community/netinfo": "^11.3.2", "@react-native-firebase/app": "^20.1.0", "@react-native-firebase/messaging": "^20.1.0", "@react-navigation/bottom-tabs": "^6.5.20", "@react-navigation/native": "^6.1.17", "@react-navigation/native-stack": "^6.9.26", "@shopify/flash-list": "1.6.4", "appcenter": "^5.0.1", "appcenter-analytics": "^5.0.1", "appcenter-crashes": "^5.0.1", "axios": "^1.7.2", "geolib": "^3.3.4", "i18next": "^23.11.5", "moment": "^2.30.1", "moment-timezone": "^0.5.45", "native-base": "^3.4.28", "patch-package": "^8.0.0", "react": "18.2.0", "react-native": "0.73.8", "react-native-android-location-enabler": "^2.0.1", "react-native-animatable": "^1.4.0", "react-native-audio-record": "^0.2.2",
"react-native-background-fetch": "^4.2.5", "react-native-background-geolocation": "^4.10.0", "react-native-code-push": "^8.2.2", "react-native-device-info": "^11.1.0", "react-native-doc-preview": "^0.2.0", "react-native-document-picker": "^9.3.0", "react-native-dropdown-picker": "^5.4.6", "react-native-file-viewer": "^2.1.5", "react-native-fs": "^2.20.0", "react-native-geolocation-service": "^5.3.1", "react-native-gesture-handler": "2.16.2", "react-native-image-crop-picker": "^0.41.1", "react-native-image-picker": "^7.1.2", "react-native-map-link": "^3.4.1", "react-native-maps": "1.15.4", "react-native-material-dropdown-v2-fixed": "^0.11.3", "react-native-modal-datetime-picker": "^17.1.0", "react-native-pager-view": "6.3.1", "react-native-paper": "^5.12.3", "react-native-permissions": "4.1.5", "react-native-progress": "^5.0.1", "react-native-prompt-android": "^1.1.0", "react-native-radio-buttons-group": "^3.1.0", "react-native-rate": "^1.2.12", "react-native-safe-area-context": "4.10.1", "react-native-screens": "3.31.1", "react-native-signature-capture": "^0.4.12", "react-native-simple-radio-button": "^2.7.4", "react-native-size-matters": "^0.4.2", "react-native-svg": "^15.3.0", "react-native-switch-toggle": "^2.2.1", "react-native-tab-view": "^3.5.2", "react-native-toggle-calendar": "^1.0.3", "react-native-vector-icons": "^10.1.0", "react-native-video": "^5.2.1", "react-native-video-helper-fork": "^1.0.3", "react-native-video-player": "^0.14.0", "react-native-webview": "^13.10.3", "react-redux": "^9.1.2", "recyclerlistview": "^4.2.1", "redux": "^5.0.1", "redux-devtools-extension": "^2.13.9", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-persist-transform-encrypt": "^5.1.1", "redux-thunk": "2.4.2", "rn-fetch-blob": "^0.12.0", "sp-react-native-in-app-updates": "^1.4.0" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@bugsnag/cli": "^2.3.0", "@react-native/babel-preset": "0.73.21", "@react-native/eslint-config": "0.73.2", "@react-native/metro-config": "0.73.5", "@react-native/typescript-config": "0.73.1", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "eslint": "^8.19.0", "jest": "^29.6.3", "prettier": "2.8.8", "react-test-renderer": "18.2.0", "typescript": "5.0.4" }, "engines": { "node": ">=18" } }

vksgautam1986 commented 1 week ago

last time i remember the issue i got bcs of bugsnag for android so i removed the bugsnag for android. now i tried again but this time not catching crashes https://github.com/transistorsoft/react-native-background-geolocation/issues/2012

matthewjhowells commented 1 week ago

Hi @,

Could you please share some more details on the crash you are seeing (e.g. a stacktrace) so that we can investigate this further? It would also be useful if you could let us know which Android SDK your app is running in when it crashes?

Could you also please let us know how you have setup BugSnag in your app? For instance, did you use the bugsnag-react-native-cli as documented here or did you perform a manual setup?

If any of these details could include sensitive information, please feel free to share this with us directly via support@bugsnag.com rather than posting it on this issue.

vksgautam1986 commented 5 days ago
  1. Yes i am using bugsnag-react-native-cli. command -- npx @bugsnag/react-native-cli init

  2. Android>Build.gradle--> buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34 appCompatVersion = "1.4.2" playServicesLocationVersion = "21.0.1" googlePlayServicesLocationVersion="21.0.1" ndkVersion = "25.1.8937393" kotlinVersion = "1.8.0"

    } subprojects { subproject -> afterEvaluate{ if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) { android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion } } } } repositories { mavenCentral() google() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.bugsnag:bugsnag-android-gradle-plugin:8.+") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") classpath 'com.google.gms:google-services:4.3.15'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

    } }

allprojects {
repositories { // Required for react-native-background-geolocation maven { url("${project(':react-native-background-geolocation').projectDir}/libs") } maven { url 'https://developer.huawei.com/repo/' } // Required for react-native-background-fetch maven { url("${project(':react-native-background-fetch').projectDir}/libs") } } } apply plugin: "com.facebook.react.rootproject"

  1. Android>app>build.gradle--> apply plugin: "com.android.application" apply plugin: "org.jetbrains.kotlin.android" apply plugin: "com.facebook.react"

/**

// background-geolocation Project background_geolocation = project(':react-native-background-geolocation') apply from: "${background_geolocation.projectDir}/app.gradle"

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"]

}

/**

def enableProguardInReleaseBuilds = false

def enableShrinkResource = false

/**

android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion

 namespace "xxxxxxxx"
defaultConfig {
    applicationId "xxxxxxxxx"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 74
    versionName '2.43'

}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
    release {
        if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
            storeFile file(MYAPP_UPLOAD_STORE_FILE)
            storePassword MYAPP_UPLOAD_STORE_PASSWORD
            keyAlias MYAPP_UPLOAD_KEY_ALIAS
            keyPassword MYAPP_UPLOAD_KEY_PASSWORD
        }
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        shrinkResources enableShrinkResource  
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"

    }
}

  packagingOptions {
    pickFirst "lib/armeabi-v7a/libc++_shared.so"
    pickFirst "lib/arm64-v8a/libc++_shared.so"
    pickFirst "lib/x86/libc++_shared.so"
    pickFirst "lib/x86_64/libc++_shared.so"
}

}

dependencies {
implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.android.support:multidex:2.0.1' implementation project(':react-native-code-push')

implementation("com.facebook.soloader:soloader:0.10.4")     // for soloader issue crash for this RN version

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

}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply plugin: "com.bugsnag.android.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" apply plugin: 'com.google.gms.google-services'

  1. Android manifest--> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

    <application android:name=".MainApplication" android:usesCleartextTraffic="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" tools:replace="android:allowBackup" android:requestLegacyExternalStorage="true">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="REDACTED" />
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="REDACTED" />
    
    <meta-data android:name="com.bugsnag.android.API_KEY" android:value="Secter Key number pasted here" />

  2. Mainapplication.java package xxxxxxxxxxxx;

import com.bugsnag.android.Bugsnag import com.microsoft.codepush.react.CodePush; import android.database.CursorWindow; import java.lang.reflect.Field; import android.app.Application; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactHost; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load; import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost; import com.facebook.react.defaults.DefaultReactNativeHost; import com.facebook.soloader.SoLoader;

class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { override fun getPackages(): List = PackageList(this).packages.apply { // Packages that cannot be autolinked yet can be added manually here, for example: add(AesEncryptionPackage()) }

    override fun getJSBundleFile(): String = CodePush.getJSBundleFile()

    override fun getJSMainModuleName(): String = "index"

    override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

     override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED

    override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
  }

override fun onCreate() { super.onCreate() Bugsnag.start(this) SoLoader.init(this, false) try { val field = CursorWindow::class.java.getDeclaredField("sCursorWindowSize") field.isAccessible = true field.set(null, 100 1024 1024) // 100MB is the new size } catch (e: Exception) { // Handle the exception if needed } if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { // If you opted-in for the New Architecture, we load the native entry point for this app. load() } } }

vksgautam1986 commented 5 days ago

I will try to create a seperate github branch where if i can reproduce this . then i will share that project with you guys

foygl commented 4 days ago

@vksgautam1986 I redacted the value of com.google.android.geo.API_KEY from the manifest you pasted yesterday. You may want to look at rotating that key if it is active, as someone may be able to use it and cost you money.