Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes without warning after following manual configuration exactly (not using react-native-link) #600

Closed
chijaoSMU opened this issue Oct 30, 2018 · 13 comments

Comments

@chijaoSMU
Copy link

chijaoSMU commented Oct 30, 2018

Your Environment

  • Plugin version: "react-native-background-geolocation": "^2.14.1"
  • Platform: Android
  • OS version: 8.0.0
  • Device manufacturer / model: Samsung S9+
  • React Native version (react-native -v): react-native-cli: 2.0.1, react-native: 0.55.4
  • Plugin config: have not started using, installing the plugin

Expected Behavior

App should run on phone

Actual Behavior

It crashed without any red screen

Steps to Reproduce

Followed steps here: https://github.com/transistorsoft/react-native-background-geolocation/blob/master/help/INSTALL-ANDROID.md

Context

Running the app

Debug logs

Gradle warning states:

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.htm
Starting the logger (C:\Users\User\AppData\Local\Android\Sdk/platform-tools/adb logcat *:S ReactNative:V ReactNativeJS:V)...
--------- beginning of crash
--------- beginning of main
10-30 15:12:46.463 26125 26125 D ReactNative: ReactInstanceManager.ctor()
10-30 15:12:46.525 26125 26125 D ReactNative: ReactInstanceManager.createReactContextInBackground()
10-30 15:12:46.525 26125 26125 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
10-30 15:13:09.257 26125 26125 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
10-30 15:13:09.260 26125 26125 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
10-30 15:13:09.261 26125 26125 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
10-30 15:13:09.293 26125 27570 D ReactNative: ReactInstanceManager.createReactContext()
10-30 15:14:12.044 27755 27755 D ReactNative: ReactInstanceManager.ctor()
10-30 15:14:12.095 27755 27755 D ReactNative: ReactInstanceManager.createReactContextInBackground()
10-30 15:14:12.095 27755 27755 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
10-30 15:14:12.097 27755 27755 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
10-30 15:14:12.098 27755 27755 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
10-30 15:14:12.098 27755 27755 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
10-30 15:14:12.111 27755 27783 D ReactNative: ReactInstanceManager.createReactContext()
10-30 15:20:46.155  1871  1871 D ReactNative: ReactInstanceManager.ctor()
10-30 15:20:46.222  1871  1871 D ReactNative: ReactInstanceManager.createReactContextInBackground()
10-30 15:20:46.222  1871  1871 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
10-30 15:20:51.142  1871  1871 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
10-30 15:20:51.143  1871  1871 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
10-30 15:20:51.143  1871  1871 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
10-30 15:20:51.162  1871  2560 D ReactNative: ReactInstanceManager.createReactContext()
--------- beginning of system
10-30 15:21:54.418  2667  2667 D ReactNative: ReactInstanceManager.ctor()
10-30 15:21:54.446  2667  2667 D ReactNative: ReactInstanceManager.createReactContextInBackground()
10-30 15:21:54.446  2667  2667 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
10-30 15:21:54.448  2667  2667 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
10-30 15:21:54.449  2667  2667 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
10-30 15:21:54.449  2667  2667 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
10-30 15:21:54.466  2667  3698 D ReactNative: ReactInstanceManager.createReactContext()
@web75018
Copy link

web75018 commented Nov 2, 2018

Hi Chris.
The same thing too.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.location.ActivityRecognitionResult" on path:

"react": "16.5.0",
"react-native": "0.57.1"

buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 18
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
googlePlayServicesVersion = '11.0.4'
androidMapsUtilsVersion = '0.5'
}
Project / build.gradle
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "$rootDir/../node_modules/react-native/android" }
maven { url 'https://maven.google.com' }
maven { url "$rootDir/../node_modules/react-native-background-geolocation/android/libs" }
maven { url "$rootDir/../node_modules/react-native-background-fetch/android/libs" }
google()
}
}

Project / app / build.gradle
dependencies {
compile project(':react-native-background-fetch')
compile project(':react-native-background-geolocation')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-maps')
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 ('com.google.android.gms:play-services-gcm:10.0.1') {
force = true;
}
}

@christocracy
Copy link
Member

When providing a crash log, use the unfiltered $ adb logcat. You're filtering out the stacktrace when you use *:S ...

@christocracy
Copy link
Member

christocracy commented Nov 2, 2018

@web75018 You're using an insufficient play-services:location version 11.0.4.

The minimum supported version is 11.2.0 but you should always strive to use the latest available version, which is 16.0.0

And you can get rid of all this junk too because react-native-maps will align itself to the googlePlayServicesVersion variable.:

compile project(':react-native-maps')
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 ('com.google.android.gms:play-services-gcm:10.0.1') {
force = true;
}

And are you aware that you're including react-native-maps twice? Your gradle config is a mess.

compile project(':react-native-maps')
compile(project(':react-native-maps')) {

@web75018
Copy link

web75018 commented Nov 3, 2018

Thanks Chris. works well!

@chijaoSMU
Copy link
Author

chijaoSMU commented Nov 3, 2018

Sorry, attached is the full logcat, couldnt copy and paste here because it's too large, causing the browser to hang
logcat.txt

@christocracy
Copy link
Member

@chijaoSMU There is no exception caused by the plugin in your logcat.

Post the contents of the following files:

  • android/build.gradle
  • android/app/build.gradle

@chijaoSMU
Copy link
Author

android/build.gradle

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

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

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
       maven {
           url 'https://maven.google.com'
       }
       maven {
           url "$rootDir/../node_modules/react-native-background-geolocation/android/libs"
       }
       maven {
           url "$rootDir/../node_modules/react-native-background-fetch/android/libs"
       }
    }
}
ext {
    compileSdkVersion   = 27
    targetSdkVersion    = 27
    buildToolsVersion   = "27.0.3"
    supportLibVersion   = "27.1.1"
    playServicesVersion = "15.0.1"
}

android/app/build.gradle

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",
 *
 *   // 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"
]

apply from: "../../node_modules/react-native/react.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

android {
    // compileSdkVersion 27
    // buildToolsVersion '27.0.3'
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        applicationId "com.cardperks_user"
        minSdkVersion 16
        // targetSdkVersion 27
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 5
        versionName "2.3"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // 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]
            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 project(':react-native-background-geolocation')
    implementation project(':react-native-background-fetch')
    implementation project(':react-native-maps')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-linear-gradient')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    // implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
   }
   implementation 'com.google.android.gms:play-services-base:10.2.4'
   implementation 'com.google.android.gms:play-services-maps:10.2.4'
   implementation 'com.android.support:support-v4:27.1.1'


}

// 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'
}

I've also noticed that when i open MainApplication.java, vscode shows this error:

MainApplication.java isn't on the classpath. Only syntax errors will be reported

Maybe there's a problem there? Here's my mainapplication.java as well. Appreciate your help Chris! :)

package com.cardperks_user;

import android.app.Application;

import com.facebook.react.ReactApplication;
// import com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocation;
import com.transistorsoft.rnbackgroundgeolocation.*;
import com.transistorsoft.rnbackgroundfetch.RNBackgroundFetchPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.airbnb.android.react.maps.MapsPackage;
import com.BV.LinearGradient.LinearGradientPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new RNBackgroundGeolocation(),
          new RNBackgroundFetchPackage(),
          new MainReactPackage(),
            new VectorIconsPackage(),
            new MapsPackage(),
            new LinearGradientPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

@chijaoSMU chijaoSMU reopened this Nov 6, 2018
@christocracy
Copy link
Member

christocracy commented Nov 6, 2018

get rid of this:

-implementation(project(':react-native-maps')){
-       exclude group: 'com.google.android.gms', module: 'play-services-base'
-       exclude group: 'com.google.android.gms', module: 'play-services-maps'
-   }
-   implementation 'com.google.android.gms:play-services-base:10.2.4'
-   implementation 'com.google.android.gms:play-services-maps:10.2.4'
+implementation "com.android.support:support-v4:$rootProject.supportLibVersion"
+implementation project(':react-native-maps')

@chijaoSMU
Copy link
Author

It still crashes without red screen.

Here's the logcat
logcat1.txt

@christocracy
Copy link
Member

Your exception is caused by react-native-maps, not background-geolocation.

What version of react-native-maps do you have installed?

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/maps/GoogleMapOptions;
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.airbnb.android.react.maps.AirMapManager.<init>(AirMapManager.java:55)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.airbnb.android.react.maps.MapsPackage.createViewManagers(MapsPackage.java:39)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:173)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:130)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:127)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:106)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1172)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1142)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1080)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:911)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:764)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.GoogleMapOptions
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at java.lang.VMClassLoader.findLoadedClass(Native Method)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
11-06 10:50:53.744 31304 32143 E AndroidRuntime: 	... 15 more

@web75018
Copy link

web75018 commented Nov 6, 2018

hi Chijao,
i had the same problem, and fixed it by adding (android/app/build.gradle):

    def playServicesVersion = "16.0.0"
    if (rootProject.ext.hasProperty('playServicesVersion')) {
        playServicesVersion = rootProject.ext.playServicesVersion
    } else if (rootProject.ext.hasProperty('googlePlayServicesVersion')) {
        playServicesVersion = rootProject.ext.googlePlayServicesVersion
    }    
    compile project(':react-native-maps')
    compile "com.google.android.gms:play-services-base:+"
    compile "com.google.android.gms:play-services-maps:+"
    compile ('com.google.android.gms:play-services-gcm:16.0.0') {
        force = true;
    }

@SMuncal
Copy link

SMuncal commented Jun 26, 2023

Hi @christocracy

I have a current issue, same with them, but the IOS React native works well and has no errors.
happens when the Android application is installed on my device or in the emulator and tried to open it, resulting in the application crashing and closing.

Kindly see the attached note as a reference for gradle

android_gradle.txt

gradle.txt

@christocracy
Copy link
Member

You’re posting on a closed issue from 2018. Post a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants