Crashes for iOS, doesn’t compile on Android

Hey!
I could not find similar issue in the issues so I’m posting here.
I’m trying to integrate react-native-firebase to use Analytics in my app. I followed all the steps in the documentation, but without any success. I’m trying to make it working for both platforms- iOS and Android.

TL;DR

App compiles for iOS but crashes just after launch.
The app does not compile for Android and results in the following error:

A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.google.gms.google-services']
   > For input string: "+"

What happens on iOS?

react-native run-ios command compiles the project successfully, uploads it to the simulator, packager packs the bundle, the app starts but hangs for a bit and crashes/closes. When I try to launch it again the same happens.

Current setup for iOS:

I have GoogleService-Info.plist residing in ios project next to Info.plist file.

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "ReactNativeConfig.h"
#import <BugsnagReactNative/BugsnagReactNative.h>
#import <Firebase.h>

@import GoogleMaps;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSString *GOOGLE_MAPS_API_KEY = [ReactNativeConfig envFor:@"GOOGLE_MAPS_API_KEY"];
  NSURL *jsCodeLocation;
  [GMSServices provideAPIKey:GOOGLE_MAPS_API_KEY];
  [BugsnagReactNative start];
  [FIRApp configure];
  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  #else
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  #endif
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"app"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

@end

Podfile

# You Podfile should look similar to this file. React Native currently does not support use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'app' do
  pod 'React', path: '../node_modules/react-native', :subspecs => [
    'Core'
  ]

  pod 'GoogleMaps'  # <~~ remove this line if you do not want to support GoogleMaps on iOS

  pod 'Firebase/Core'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase'
  pod 'Firebase/Analytics'

end

my custom module imported in another module

import RNFirebase from 'react-native-firebase'

const configurationOptions = {
  debug: __DEV__
}

const firebase = RNFirebase.initializeApp(configurationOptions)

export default firebase

What happens on Android?

cd android && ./gradlew clean && cd .. && react-native run-android running this command results in the error below:

Reading env from: .env

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/lukaleli/app/android/app/build.gradle' line: 184

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.google.gms.google-services']
   > For input string: "+"

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.569 secs

Current setup for Android:

google-services.json residing in android/app directory

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
import groovy.json.JsonSlurper

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'com.google.gms:google-services:3.0.0'

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

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    ext {
        def npmVersion = getNpmVersionArray()
        versionMajor = npmVersion[0]
        versionMinor = npmVersion[1]
        versionPatch = npmVersion[2]
    }
}

def getNpmVersion() {
    def inputFile = new File("$rootDir/../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}

def getNpmVersionArray() { // major [0], minor [1], patch [2]
    def (major, minor, patch) = getNpmVersion().tokenize('.')
    return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}

android/app/build.gradle (only dependency part)

// ...

dependencies {
    compile project(':react-native-permissions')
    compile project(':react-native-device-info')
    compile project(':react-native-config')
    compile project(':bugsnag-react-native')
    compile project(':lottie-react-native')
    compile project(':react-native-fs')
    compile project(':react-native-vector-icons')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-camera')
    compile(project(':react-native-maps')){
            exclude group: 'com.google.android.gms', module: 'play-services-base'
            exclude group: 'com.google.android.gms', module: 'play-services-maps'
        }
    compile 'com.google.android.gms:play-services-base:+'
    compile 'com.google.android.gms:play-services-maps:+'
    compile project(':react-native-localization')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile 'com.facebook.fresco:animated-gif:0.11.0'
    compile(project(':react-native-firebase')) {
        transitive = false
      }
    compile "com.google.firebase:firebase-core:11.0.0"
    compile "com.google.firebase:firebase-analytics:11.0.0"
}


// 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 plugin: 'com.google.gms.google-services'

Tried solutions

For android I tried to exclude google services dependencies from possibly colliding libraries (react-native-maps and react-native-device-info), but with no success. (idea taken from: https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f )

For iOS I have no clue what to look for as long as I cannot catch the native crashes when running the app in the simulator from the cmd. It just crashes silently.

I’m struggling with this issue the second day already and I’m pulling my hair off… Did anybody encounter something similar?

Thanks in advance!

Environment

  1. Target Platform: iOS and Android
  2. Development Operating System : macOS Sierra
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version: 0.41.2
  5. RNFirebase Version: 2.0.2

Author: Fantashit

2 thoughts on “Crashes for iOS, doesn’t compile on Android

  1. iOS
    Yes, unfortunately pasting the file into the directory doesn’t automatically add the file to the iOS project. You need to manually add it (which I only know how to do within XCode) by:

    • Right click on your project
    • Click “Add files to ‘project name'”
    • Select the .plist file
    • Click ok

    Android
    Ah, ok, thanks for confirming. Are you able to run with the --stacktrace flag? This will hopefully give some more information…

  2. Ok, I will post how I made it working for android as well here. The problem is with colliding play services modules. I basically excluded them from the libraries that use them (in my case: react-native-device-info and react-native-maps) and added them as a separate dependencies in my build.gradle file with fixed version.

    dependencies {
        compile project(':react-native-permissions')
        compile (project(':react-native-device-info')){
            exclude group: 'com.google.android.gms'
        }
        compile project(':react-native-config')
        compile project(':bugsnag-react-native')
        compile project(':lottie-react-native')
        compile project(':react-native-fs')
        compile project(':react-native-vector-icons')
        compile project(':react-native-linear-gradient')
        compile project(':react-native-camera')
        compile(project(':react-native-maps')){
            exclude group: 'com.google.android.gms'
        }
        compile ('com.google.android.gms:play-services-base:11.0.0') {
            force = true
        }
        compile ('com.google.android.gms:play-services-maps:11.0.0') {
            force = true
        }
        compile ('com.google.android.gms:play-services-gcm:11.0.0') { 
            force = true 
        }
        compile project(':react-native-localization')
        compile fileTree(dir: "libs", include: ["*.jar"])
        compile "com.android.support:appcompat-v7:23.0.1"
        compile "com.facebook.react:react-native:+"  // From node_modules
        compile 'com.facebook.fresco:animated-gif:0.11.0'
        compile(project(':react-native-firebase')) {
            transitive = false
          }
        compile "com.google.firebase:firebase-core:11.0.0"
        compile "com.google.firebase:firebase-analytics:11.0.0"
    }

    Hope that it’ll help someone.
    Issue can be closed now. Thanks for your help!

Comments are closed.

Crashes for iOS, doesn’t compile on Android

Hey!
I could not find similar issue in the issues so I’m posting here.
I’m trying to integrate react-native-firebase to use Analytics in my app. I followed all the steps in the documentation, but without any success. I’m trying to make it working for both platforms- iOS and Android.

TL;DR

App compiles for iOS but crashes just after launch.
The app does not compile for Android and results in the following error:

A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.google.gms.google-services']
   > For input string: "+"

What happens on iOS?

react-native run-ios command compiles the project successfully, uploads it to the simulator, packager packs the bundle, the app starts but hangs for a bit and crashes/closes. When I try to launch it again the same happens.

Current setup for iOS:

I have GoogleService-Info.plist residing in ios project next to Info.plist file.

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "ReactNativeConfig.h"
#import <BugsnagReactNative/BugsnagReactNative.h>
#import <Firebase.h>

@import GoogleMaps;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSString *GOOGLE_MAPS_API_KEY = [ReactNativeConfig envFor:@"GOOGLE_MAPS_API_KEY"];
  NSURL *jsCodeLocation;
  [GMSServices provideAPIKey:GOOGLE_MAPS_API_KEY];
  [BugsnagReactNative start];
  [FIRApp configure];
  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  #else
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  #endif
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"app"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

@end

Podfile

# You Podfile should look similar to this file. React Native currently does not support use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'app' do
  pod 'React', path: '../node_modules/react-native', :subspecs => [
    'Core'
  ]

  pod 'GoogleMaps'  # <~~ remove this line if you do not want to support GoogleMaps on iOS

  pod 'Firebase/Core'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase'
  pod 'Firebase/Analytics'

end

my custom module imported in another module

import RNFirebase from 'react-native-firebase'

const configurationOptions = {
  debug: __DEV__
}

const firebase = RNFirebase.initializeApp(configurationOptions)

export default firebase

What happens on Android?

cd android && ./gradlew clean && cd .. && react-native run-android running this command results in the error below:

Reading env from: .env

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/lukaleli/app/android/app/build.gradle' line: 184

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.google.gms.google-services']
   > For input string: "+"

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.569 secs

Current setup for Android:

google-services.json residing in android/app directory

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
import groovy.json.JsonSlurper

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'com.google.gms:google-services:3.0.0'

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

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    ext {
        def npmVersion = getNpmVersionArray()
        versionMajor = npmVersion[0]
        versionMinor = npmVersion[1]
        versionPatch = npmVersion[2]
    }
}

def getNpmVersion() {
    def inputFile = new File("$rootDir/../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}

def getNpmVersionArray() { // major [0], minor [1], patch [2]
    def (major, minor, patch) = getNpmVersion().tokenize('.')
    return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}

android/app/build.gradle (only dependency part)

// ...

dependencies {
    compile project(':react-native-permissions')
    compile project(':react-native-device-info')
    compile project(':react-native-config')
    compile project(':bugsnag-react-native')
    compile project(':lottie-react-native')
    compile project(':react-native-fs')
    compile project(':react-native-vector-icons')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-camera')
    compile(project(':react-native-maps')){
            exclude group: 'com.google.android.gms', module: 'play-services-base'
            exclude group: 'com.google.android.gms', module: 'play-services-maps'
        }
    compile 'com.google.android.gms:play-services-base:+'
    compile 'com.google.android.gms:play-services-maps:+'
    compile project(':react-native-localization')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile 'com.facebook.fresco:animated-gif:0.11.0'
    compile(project(':react-native-firebase')) {
        transitive = false
      }
    compile "com.google.firebase:firebase-core:11.0.0"
    compile "com.google.firebase:firebase-analytics:11.0.0"
}


// 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 plugin: 'com.google.gms.google-services'

Tried solutions

For android I tried to exclude google services dependencies from possibly colliding libraries (react-native-maps and react-native-device-info), but with no success. (idea taken from: https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f )

For iOS I have no clue what to look for as long as I cannot catch the native crashes when running the app in the simulator from the cmd. It just crashes silently.

I’m struggling with this issue the second day already and I’m pulling my hair off… Did anybody encounter something similar?

Thanks in advance!

Environment

  1. Target Platform: iOS and Android
  2. Development Operating System : macOS Sierra
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant):
  4. React Native version: 0.41.2
  5. RNFirebase Version: 2.0.2

Author: Fantashit

1 thought on “Crashes for iOS, doesn’t compile on Android

  1. iOS
    Yes, unfortunately pasting the file into the directory doesn’t automatically add the file to the iOS project. You need to manually add it (which I only know how to do within XCode) by:

    • Right click on your project
    • Click “Add files to ‘project name'”
    • Select the .plist file
    • Click ok

    Android
    Ah, ok, thanks for confirming. Are you able to run with the --stacktrace flag? This will hopefully give some more information…

Comments are closed.