invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.63k stars 2.2k forks source link

🔥 react-native run-android crashes on android emulator #3429

Closed 16oh4 closed 4 years ago

16oh4 commented 4 years ago

Issue

Android app crashes after it downloads the JS bundle. New expo init bare workflow application.

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [x ] I'm not using Pods - [] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? I am using Android 9 with this emulated device: ![image](https://user-images.githubusercontent.com/37783822/78910358-74903d80-7a4a-11ea-86e3-1995fec6ec43.png) I ran adb -e logcat com.sixthapp:V *:S ``` 09:13:52.001 __________________________ 04-09 09:13:52.001 10624 10635 I com.sixthapp: Background concurrent copying GC freed 6686(790KB) AllocSpace objects, 1(20KB) LOS objects, 50% free, 2MB/4MB, paused 1.382ms total 111.925ms 04-09 09:14:32.704 10701 10701 I com.sixthapp: Not late-enabling -Xcheck:jni (already on) 04-09 09:14:32.733 10701 10701 W com.sixthapp: Unexpected CPU variant for X86 using defaults: x86 04-09 09:14:33.521 10701 10701 W com.sixthapp: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking) 04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking) 04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking) 04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking) 04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking) 04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection) 04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection) 04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection) 04-09 09:14:33.869 10701 10701 W com.sixthapp: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) 04-09 09:14:33.869 10701 10701 W com.sixthapp: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection) 04-09 09:14:34.305 10701 10701 W com.sixthapp: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking) 04-09 09:14:34.392 10701 10712 I com.sixthapp: Background concurrent copying GC freed 9899(897KB) AllocSpace objects, 3(124KB) LOS objects, 50% free, 2MB/5MB, paused 11.869ms total 126.409ms 04-09 09:14:35.361 10701 10712 I com.sixthapp: Background concurrent copying GC freed 7488(544KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 5MB/10MB, paused 512us total 350.638ms ``` Package.json: ``` { "main": "index.js", "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "web": "expo start --web", "start": "react-native start", "client": "expo start", "test": "jest" }, "dependencies": { "@react-native-firebase/app": "^6.4.0", "expo": "~37.0.3", "expo-updates": "~0.1.0", "paper": "^0.12.4", "react": "~16.9.0", "react-dom": "~16.9.0", "react-native": "^0.62.2", "react-native-gesture-handler": "~1.6.0", "react-native-reanimated": "~1.7.0", "react-native-screens": "~2.2.0", "react-native-unimodules": "~0.9.0", "react-native-web": "~0.11.7" }, "devDependencies": { "@babel/core": "~7.9.0", "@types/react": "~16.9.23", "@types/react-native": "~0.61.23", "babel-preset-expo": "~8.1.0", "jest-expo": "~37.0.0", "typescript": "~3.8.3" }, "jest": { "preset": "react-native" }, "private": true } ``` I think these are enabled by expo by default when I run ``` PS G:\Documents\ReactNative\seventhapp> yarn android yarn run v1.21.1 $ react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1161 file(s) to forward-jetify. Using 4 workers... ``` - [x ] my application is an AndroidX application? - [x ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 21 compileSdkVersion = 28 targetSdkVersion = 28 } repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:3.5.3") classpath("com.google.gms:google-services:4.2.0") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } google() jcenter() maven { url 'https://jitpack.io' } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation * entryFile: "index.android.js", * * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format * bundleCommand: "ram-bundle", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ project.ext.react = [ entryFile: "index.js", enableHermes: false, bundleInRelease: false ] apply from: '../../node_modules/react-native-unimodules/gradle.groovy' apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/expo-updates/expo-updates.gradle" /** * Set this to true 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. */ def enableHermes = project.ext.react.get("enableHermes", false); android { compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "com.sixthapp" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://facebook.github.io/react-native/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } // 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: // https://developer.android.com/studio/build/configure-apk-splits.html 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 = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // From node_modules addUnimodulesDependencies() if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } 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.compile into 'libs' } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply plugin: "com.google.gms.google-services" ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'sixthapp' apply from: '../node_modules/react-native-unimodules/gradle.groovy' includeUnimodulesProjects() apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' ``` #### `MainApplication.java`: ```java package com.sixthapp; import android.app.Application; import android.content.Context; import android.net.Uri; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; import com.sixthapp.generated.BasePackageList; import org.unimodules.adapters.react.ReactAdapterPackage; import org.unimodules.adapters.react.ModuleRegistryAdapter; import org.unimodules.adapters.react.ReactModuleRegistryProvider; import org.unimodules.core.interfaces.Package; import org.unimodules.core.interfaces.SingletonModule; import expo.modules.constants.ConstantsPackage; import expo.modules.permissions.PermissionsPackage; import expo.modules.filesystem.FileSystemPackage; import expo.modules.updates.UpdatesController; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import javax.annotation.Nullable; public class MainApplication extends Application implements ReactApplication { private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider( new BasePackageList().getPackageList(), null ); private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { List packages = new PackageList(this).getPackages(); packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider)); return packages; } @Override protected String getJSMainModuleName() { return "index"; } @Override protected @Nullable String getJSBundleFile() { if (BuildConfig.DEBUG) { return super.getJSBundleFile(); } else { return UpdatesController.getInstance().getLaunchAssetFile(); } } @Override protected @Nullable String getBundleAssetName() { if (BuildConfig.DEBUG) { return super.getBundleAssetName(); } else { return UpdatesController.getInstance().getBundleAssetName(); } } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this); // Remove this line if you don't want Flipper enabled if (!BuildConfig.DEBUG) { UpdatesController.initialize(this); } } /** * Loads Flipper in React Native templates. * * @param context */ private static void initializeFlipper(Context context) { if (BuildConfig.DEBUG) { try { /* We use reflection here to pick up the class that initializes Flipper, since Flipper library is not available in release mode */ Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); aClass.getMethod("initializeFlipper", Context.class).invoke(null, context); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** **Ignore Android SDK, Android Studio, and Java parameters. I have these installed on G:\** ``` System: OS: Windows 10 10.0.18362 CPU: (4) x64 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz Memory: 734.32 MB / 7.87 GB Binaries: Node: 13.11.0 - C:\Users\admin\AppData\Local\Temp\yarn--1586443855345-0.7685545292656126\node.CMD Yarn: 1.21.1 - C:\Users\admin\AppData\Local\Temp\yarn--1586443855345-0.7685545292656126\yarn.CMD npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found IDEs: Android Studio: Not Found Languages: Java: Not Found Python: Not Found npmPackages: @react-native-community/cli: Not Found react: ~16.9.0 => 16.9.0 react-native: ^0.62.2 => 0.62.2 npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [x] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.40` - **`Firebase` module(s) you're using that has the issue:** - `Not even imported to any .tsx file yet. A new expo bare workflow project.` - **Are you using `TypeScript`?** - `Y` & `3.8.3` - **Are you using `Expo`?** - `Y` & `37.0.3`


mikehardy commented 4 years ago

crash with no stack trace?

16oh4 commented 4 years ago

@mikehardy Hello Mike, what stack trace are you asking for? Whenever I open the app, it immediately crashes on the EMULATOR, but not on the JS Server; The JS Server happily serves the bundles.

To clarify, the app simply closes on the emulator saying (Stopped working).

However, the app does build using

$ react-native run-android
mikehardy commented 4 years ago

adb logcat - if an app crashes there is always a stack trace, that's how you get it on android. For iOS you run the app from Xcode then the stack shows up in there, otherwise there's no way to know why it crashed.

16oh4 commented 4 years ago

@mikehardy I put an adb logcat in the post. Is this one good or which one should I run? I used

$ adb -e logcat com.sixthapp:V *:S
09:13:52.001
__________________________
04-09 09:13:52.001 10624 10635 I com.sixthapp: Background concurrent copying GC freed 6686(790KB) AllocSpace objects, 1(20KB) LOS objects, 50% free, 2MB/4MB, paused 1.382ms total 111.925ms
04-09 09:14:32.704 10701 10701 I com.sixthapp: Not late-enabling -Xcheck:jni (already on)
04-09 09:14:32.733 10701 10701 W com.sixthapp: Unexpected CPU variant for X86 using defaults: x86
04-09 09:14:33.521 10701 10701 W com.sixthapp: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
04-09 09:14:33.523 10701 10701 W com.sixthapp: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection)
04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection)
04-09 09:14:33.752 10701 10701 W com.sixthapp: Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection)
04-09 09:14:33.869 10701 10701 W com.sixthapp: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
04-09 09:14:33.869 10701 10701 W com.sixthapp: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
04-09 09:14:34.305 10701 10701 W com.sixthapp: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
04-09 09:14:34.392 10701 10712 I com.sixthapp: Background concurrent copying GC freed 9899(897KB) AllocSpace objects, 3(124KB) LOS objects, 50% free, 2MB/5MB, paused 11.869ms total 126.409ms
04-09 09:14:35.361 10701 10712 I com.sixthapp: Background concurrent copying GC freed 7488(544KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 5MB/10MB, paused 512us total 350.638ms
mikehardy commented 4 years ago

Yes, I saw that but it did not have a stack trace :-). Note that you put a filtered logcat in the post. I recommended just using adb logcat (i.e., unfiltered). The stack trace must be there, we need it to proceed

16oh4 commented 4 years ago

@mikehardy Hey Mike I made a new

$ expo init

bare workflow project and now I've got everything setup. I must have edited some files wrong. I can use the Firebase features now. If you want me to test this case out for you, then I certainly can for your team's benefit.

Thanks so much!

mikehardy commented 4 years ago

If it's working for you, it works for me :-), have a nice weekend