react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Application crashed due to BackgroundGeolocation.ready
Your Environment
- Plugin version:
- Platform: Android
- OS version: 12
- Device manufacturer / model: Realme 13
- React Native version (
react-native -v): 0.64.2 - Plugin config
import React from 'react';
import BackgroundGeolocation from 'react-native-background-geolocation';
import Config from 'react-native-config';
const LOCATIONURL = Config.LOCATION_URL;
const TransistorSoftBackgroundLocation = async (driverData) => {
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 0,
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
// debug: true,
fastestLocationUpdateInterval: 5000,
foregroundService: true,
}).then((state) => {
console.log('MYSTATE==>', JSON.stringify(state));
console.log('================================================');
if (!state.enabled) {
console.log('MyStateEnable', state.enabled);
//BackgroundGeolocation.start();
}
});
// This handler fires whenever bgGeo receives a location update.
BackgroundGeolocation.onLocation(
(location) => {
postLocationsToServer(
location.coords.latitude,
location.coords.longitude,
driverData,
);
// console.log('[location] ', location);
},
(error) => {
console.log('[location] ERROR: ', error);
},
);
// This handler fires when movement states changes (stationary->moving; moving->stationary)
BackgroundGeolocation.onMotionChange((location) => {});
// This handler fires on HTTP responses
BackgroundGeolocation.onHttp((response) => {
console.log('[http] ', response);
});
// This event fires when a change in motion activity is detected
BackgroundGeolocation.onActivityChange((activityEvent) => {
console.log('[activitychange] ', activityEvent);
});
// This event fires when the user toggles location-services authorization
BackgroundGeolocation.onProviderChange((providerEvent) => {
console.log('[providerchange] ', JSON.stringify(providerEvent));
});
};
Expected Behavior
It should be worked properly without app crash
Actual Behavior
App getting crashed with out showing any error
Steps to Reproduce
- I just invoked the TransistorSoftBackgroundLocation function
- App getting crashed
Context
Debug logs
[providerchange] {"accuracyAuthorization":0,"gps":true,"status":3,"enabled":true,"network":false}
PASTE_YOUR_LOGS_HERE
`apply plugin: "com.android.application" apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
project.ext.envConfigFiles = [ envQa: ".env.qa", envProd: ".env.prod", ]
apply from: project(":react-native-config").projectDir.getPath() + "/dotenv.gradle"
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 bundlewith 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, // clean and rebuild if changing ]
// 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
/**
- 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.toLocaleStringandString.localeComparethat - 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 { ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion lintOptions { checkReleaseBuilds false } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
defaultConfig {
applicationId "com.tinting"
// missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
vectorDrawables.useSupportLibrary = true
versionCode 58
versionName "4.2.2"
multiDexEnabled true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
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
}
}
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.release
// signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
flavorDimensions "default"
productFlavors {
envProd {
resValue "string", "build_config_package", "com.tinting"
}
envQa {
resValue "string", "build_config_package", "com.tinting"
}
}
// 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 { // compile 'com.google.android.gms:play-services:16.0.1' // compile project(':reactnativenotifications') // compile project(':react-native-otp-verify') // compile project(':react-native-otp-verify') implementation fileTree(dir: "libs", include: ["*.jar"]) // implementation project(':@mauron85_react-native-background-geolocation') implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation project(':react-native-permissions') implementation project(':react-native-localize') implementation "com.facebook.react:react-native:+" implementation "com.google.android.gms:play-services-auth:16.0.1" // implementation 'com.google.android.gms:play-services-base:10.0.1' implementation "com.google.android.gms:play-services-base:+" implementation ("androidx.appcompat:appcompat:1.3.1") { version { strictly '1.3.1' } } implementation ('com.google.android.material:material:1.6.0'){ version { strictly '1.6.0' } }
// implementation 'com.google.android.gms:play-services-base:10.0.1'
// implementation project(':reactnativenotifications');
// implementation 'com.google.firebase:firebase-analytics'
// implementation fileTree(dir: "libs", include: ["*.jar"])
// implementation 'com.google.android.gms:play-services-auth:+'
// implementation 'com.google.firebase:firebase-core:16.0.7';
// implementation "com.google.android.gms:play-services-gcm:+"
// implementation platform('com.google.firebase:firebase-bom:26.0.0')
// implementation 'com.google.android.gms:play-services-base:16.0.1'
// compile ("com.google.android.gms:play-services-auth:16.1.0") {
// force = true;
// }
// implementation(project(":react-native-google-signin"))
// compile 'com.android.support:multidex:1.0.1'
// Import the BoM for the Firebase platform
// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
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' apply plugin: "kotlin-android" apply plugin: "kotlin-android-extensions" Project background_geolocation = project(':react-native-background-geolocation') apply from: "${background_geolocation.projectDir}/app.gradle" `
`// Top-level build file where you can add configuration options common to all sub-projects/modules.
// apply plugin: 'com.google.gms.google-services' // apply plugin: 'com.android.application'
buildscript {
ext {
googlePlayServicesLocationVersion = "17.0.0" // Or higher.
buildToolsVersion = "30.0.2"
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 33
supportLibVersion = "30.0.0"
googlePlayServicesAuthVersion = "16.0.1"
googlePlayServicesVersion = "17.0.0" // default: "+"
gradle3EXPERIMENTAL="yes"
kotlin_version = '1.4.10'
// gradle_version = '4.1.0'
appCompatVersion = "1.4.2"
// Or higher. Required for new AndroidX compatibility.
if (System.properties['os.arch'] == "aarch64") {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = "24.0.8215888"
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = "21.4.7075529"
}
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/android/android-tools" }
}
dependencies {
classpath('com.android.tools.build:gradle:4.0.1')
classpath 'com.google.gms:google-services:4.3.4'
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath 'com.google.android.gms:play-services-auth:16.0.1'
// classpath 'com.android.tools.build:gradle:3.0.1'
// classpath 'com.google.gms:google-services:4.1.0'
// classpath 'com.google.gms:google-services:16.1.0'
// classpath("com.google.gms:google-services:+")
// classpath("com.google.android.gms:google-services-auth:16.1.0")
// classpath 'com.google.gms:google-services:4.3.4'
// classpath 'com.google.gms:google-services:4.1.0'
// classpath 'com.android.tools.build:gradle:3.1.2' // <--- use this version or newer
// classpath 'com.google.gms:google-services:4.3.4'
// classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects { repositories { google() mavenLocal() jcenter() mavenCentral()
maven { url 'https://maven.zohodl.com' }
// maven { url "https://maven.google.com" }
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")
}
// maven {
// url 'https://maven.google.com'
// }
maven { url "https://www.jitpack.io" }
maven {
// Required for react-native-background-geolocation
url("${project(':react-native-background-geolocation').projectDir}/libs")
}
maven {
// react-native-background-fetch
url("${project(':react-native-background-fetch').projectDir}/libs")
}
maven {url 'https://developer.huawei.com/repo/'}
// maven { url 'https://maven.google.com' }
// google()
// maven { url 'https://jitpack.io' }
}
configurations.all {
resolutionStrategy {
// Remove this override in 0.65+, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
force 'androidx.core:core-ktx:1.8.0'
force 'androidx.core:core:1.9.0'
}
}
} `
When there’s a crash, the first thing you do (before posting an issue) is fetch the stacktrace from $ adb logcat. There is always a stacktrace, showing what what wrong and where.
Plugin version:
You failed to provide the version of the plugin you're using.
ext {
googlePlayServicesLocationVersion = "17.0.0" // Or higher.
Why would you use v17 from 2019? The latest version is 21.3.0
https://maven.google.com/web/index.html?q=location#com.google.android.gms:play-services-location
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.