react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

App build Failed with react-native-background-geolocation-android(2.10.0)

Open manju-ms opened this issue 9 years ago • 22 comments

Your Environment

  • Plugin version: 2.10.1
  • Platform: Android
  • React Native version (react-native -v): 0.49.3

Expected Behavior

I cloned your demo application and remove existing react-native-background-geolocation and added react-native-background-geolocation-android. After all the npm install and react-native link it is giving the error while building the app in emulator.

Actual Behavior

Build Failed with following error Bundling index.android.js [development, non-minified] ░░░░░░░░░░░░░░░░ 0.0% (0/1)SyntaxError: Unexpected token @ in JSON at position 1374 at JSON.parse () at module.exports (/home/msuser1/workspace/vicc/BGGEOAPP/rn-background-geolocation-demo/node_modules/jest-haste-map/build/worker.js:65:29) at handle (/home/msuser1/workspace/vicc/BGGEOAPP/rn-background-geolocation-demo/node_modules/worker-farm/lib/child/index.js:44:8) at process. (/home/msuser1/workspace/vicc/BGGEOAPP/rn-background-geolocation-demo/node_modules/worker-farm/lib/child/index.js:51:3) at emitTwo (events.js:106:13) at process.emit (events.js:194:7) at process.nextTick (internal/child_process.js:766:12) at _combinedTickCallback (internal/process/next_tick.js:73:7) Bundling index.android.js [development, non-minified] 0.0% (0/1), failed. Loading dependency graph...

Steps to Reproduce

  1. Cloned the Demo Application.
  2. react-native unlink react-native-background-geolocation
  3. react-native uninstall react-native-background-geolocation
  4. npm install react-native-background-geolocation-android (private respository installed through token).
  5. react-native link react-native-background-geolocation-android
  6. changed repositories { flatDir { dirs "../../node_modules/react-native-background-geolocation/android/libs" } }

with

   repositories {
      flatDir {
         dirs "../../node_modules/react-native-background-geolocation-android/android/libs"
      }
   }

Context

Building A Demo Application with the latest react-native-background-geolocation-android and understanding of the functionality of different configurations.

manju-ms avatar Nov 23 '17 08:11 manju-ms

Cloning repo without making changes works here. I wouldn't worry about trying to use the private -android repo for the demo app.

Are you sure you didn't change any javascript?

(0/1)SyntaxError: Unexpected token @ in JSON at position 1374

Did you change the import in index.android.js

I also found I had 2 new RNBackgroundGeolocation() after all the react-native unlink / react-native link. I removed one.

christocracy avatar Nov 23 '17 13:11 christocracy

Platform: Android React Native version (react-native -v): 0.45.1

I tried below steps in existing project, Previously i used react-native-background-geolocation version 2.8.4.

  1. react-native unlink react-native-background-geolocation
  2. npm uninstall react-native-background-geolocation
  3. Now i am using " npm install git+https://*************************:[email protected]:********/react-native-background-geolocation-android.git --save "
  4. react-native link react-native-background-geolocation

Now i have following changes

In android/settings.gradle 1) include ':react-native-background-geolocation' 2) project(':react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-geolocation-android/android')

in android/app/build.gradle 1) compile (project(':react-native-background-geolocation')) { exclude(group: 'com.google.android.gms', module: 'play-services-location') } 2) compile "com.android.support:appcompat-v7:26.0.1" 3) compile (name: 'tslocationmanager', ext: 'aar') 4) allprojects { repositories { jcenter() flatDir { dirs 'libs', '../../node_modules/react-native-background-geolocation-android/android/libs' } } }

in MainApplication.java

  1. import com.transistorsoft.rnbackgroundgeolocation.*;
  2. new RNBackgroundGeolocation();

in My app i am importing using below code

import BackgroundGeolocation from "react-native-background-geolocation-android";

But on call of BackgroundGeolocation.start(function(state) { });

I am getting following errors. Is there any configuration errors?

AndroidRuntime: FATAL EXCEPTION: pool-5-thread-1 11-27 20:56:44.997 8540 8588 E AndroidRuntime: Process: com.cloudscann.vic2.four, PID: 8540 11-27 20:56:44.997 8540 8588 E AndroidRuntime: java.lang.NoSuchMethodError: No static method getFusedLocationProviderClient(Landroid/content/Context;)Lcom/google/android/gms/location/FusedLocationProviderClient; in class Lcom/google/android/gms/location/LocationServices; or its super classes (declaration of 'com.google.android.gms.location.LocationServices' appears in /data/app/com.cloudscann.vic2.four-1/base.apk) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at com.transistorsoft.locationmanager.location.TSLocationManager.getLastLocation(Unknown Source) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at com.transistorsoft.locationmanager.location.TSLocationManager.getCurrentPosition(Unknown Source) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$h.a(Unknown Source) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$h.run(Unknown Source) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 11-27 20:56:44.997 8540 8588 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818) 11-27 20:56:45.020 1564 6558 W ActivityManager: Force finishing activity com.cloudscann.vic2.four/.MainActivity

manju-ms avatar Nov 27 '17 15:11 manju-ms

You're including a version of play-service-location < 11.2.0. The plugin now requires 11.2.0+ because it uses new location APIs from play-services (namely FusedLocationProviderClient).

Show me:

$ cd android
$ ./gradlew app:dependencies

christocracy avatar Nov 27 '17 16:11 christocracy

Update?

christocracy avatar Dec 05 '17 03:12 christocracy

Sorry i was away from this issue for some time, I updated the play-service-location now my android/build.gradle look like this

compile (project(':react-native-background-geolocation-android')) {
    exclude(group: 'com.google.android.gms', module: 'play-services-location')
}

compile ("com.google.android.gms:play-services-location:+") { force = true; }

compile (name: 'tslocationmanager', ext: 'aar') compile "com.android.support:appcompat-v7:26.0.1"

Now the app is working fine, But some time i will get the error and app crashes.

The error i am getting is

java.lang.NoSuchMethodError No static method getClient(Landroid/content/Context;)Lcom/google/android/gms/location/ActivityRecognitionClient; in class Lcom/google/android/gms/location/ActivityRecognition; or its super classes (declaration of 'com.google.android.gms.location.ActivityRecognition' appears in /data/app/com.cloudscann.vic2.four-1/base.apk) Unknown:-1 com.transistorsoft.locationmanager.BackgroundGeolocationService.b Unknown:-1 com.transistorsoft.locationmanager.BackgroundGeolocationService.onStartCommand ActivityThread.java:3031 android.app.ActivityThread.handleServiceArgs ActivityThread.java:-1 android.app.ActivityThread.-wrap17 ActivityThread.java:1455 android.app.ActivityThread$H.handleMessage Handler.java:102 android.os.Handler.dispatchMessage Looper.java:148 android.os.Looper.loop ActivityThread.java:5459 android.app.ActivityThread.main Method.java:-2 java.lang.reflect.Method.invoke ZygoteInit.java:728 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run ZygoteInit.java:618 com.android.internal.os.ZygoteInit.main

manju-ms avatar Dec 11 '17 11:12 manju-ms

The plugin requires play-services minimum version 11.2.0 (latest is 11.6.0 Don't use version +.

compile ("com.google.android.gms:play-services-location:11.6.0") {
force = true;
}

christocracy avatar Dec 11 '17 12:12 christocracy

if i use 11.6.0 play services, i iam getting this error while building. Could not find com.google.android.gms:play-services-location:11.6.0

manju-ms avatar Dec 12 '17 11:12 manju-ms

Review the setup docs. There’s a new maven url you must add

christocracy avatar Dec 12 '17 11:12 christocracy

Specifically, this Maven url

Google migrated to their own Maven server in 11.2.0.

christocracy avatar Dec 12 '17 12:12 christocracy

After changing the google play services to 11.6.0, it is working. I will close the issue. Thank you.

manju-ms avatar Dec 23 '17 08:12 manju-ms

I updated every plugin i'm using to 11.6.0 (ie I went into each build.gradle from the node_modules folder and looked for anything play services and changed to :11.6.0) but i'm still getting the java.lang.NoSuchMethodError: No static method getClient error.

Here's my app/build.gradle

apply plugin: "com.android.application"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

import com.android.build.OutputFile


project.ext.react = [
    entryFile: "index.js"
]



/**
 * 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 26
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.convoyerandroid"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    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"
        }
    }
    // 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
            }
        }
    }
}

repositories {
   flatDir {
       dirs "../../node_modules/react-native-background-geolocation/android/libs"
   }
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.getRequested().getGroup() == 'com.google.android.gms') {
            details.useVersion('9.8.0')
        }
    }
}

dependencies {
    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 project(':react-native-navigation')
    compile project(':react-native-background-geolocation')
    compile project(':react-native-device-info')
    compile project(':react-native-video')
    compile(name: 'tslocationmanager', ext: 'aar')
        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:11.6.0'
    compile 'com.google.android.gms:play-services-maps:11.6.0'
             compile (project(':react-native-camera')) {
    exclude group: "com.google.android.gms"
}
    compile ("com.google.android.gms:play-services-vision:11.6.0") {
    force = true;
}
    compile project(':react-native-push-notification')
    compile ('com.google.android.gms:play-services-gcm:11.6.0') {
        force = true;
    }
    compile(project(':react-native-background-geolocation')) {
  exclude group: 'com.google.android.gms', module: 'play-services-location'
}
compile 'com.google.android.gms:play-services-location:11.6.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'
}

arapocket avatar Mar 14 '18 18:03 arapocket

Are you opening your project in Android Studio? You should be seeing warnings about your app-compat-v7 version.

The base version must match your compileSdkVersion.

You have compileSdkVersion 26 yet you’re including support version of 23.0.1.

christocracy avatar Mar 14 '18 18:03 christocracy

I'm using Android Studio but I was exclusively developing for iOS before so i'm not used to all these outlandish errors.

I commented out compile "com.android.support:appcompat-v7:23.0.1 but still getting java.lang.NoSuchMethodError: No static method getClient

What exactly do I change? Also thanks for your help.

EDIT: here's what it looks like now but same error

    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.convoyerandroid"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

arapocket avatar Mar 14 '18 18:03 arapocket

You don’t comment it out. You set the correct version.

Try 26.1.0. Note how the base version 26 matches your compileSdkVersion 26.

Android Studio is warning you about this.

christocracy avatar Mar 14 '18 18:03 christocracy

It says 26.1.0 isn't available for download when I try to install it.

arapocket avatar Mar 14 '18 18:03 arapocket

Check your Android SDK Manager. Update as required.

christocracy avatar Mar 14 '18 19:03 christocracy

And ensure you have the required google maven repo

Google now hosts all its latest APIs on its own maven repo.

        maven {
            url 'https://maven.google.com'
        }

christocracy avatar Mar 14 '18 19:03 christocracy

I think I have the most recent version of everything? I even tried 26.1.1 since I already have it installed same issue

screen shot 2018-03-14 at 12 19 28 pm

I got that repo line as well.

arapocket avatar Mar 14 '18 19:03 arapocket

Android SDK Tools version does not imply support library version.

christocracy avatar Mar 14 '18 19:03 christocracy

Here's the /android/build.gradle

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

        // 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"
        }
            maven {
            url 'https://maven.google.com'
        }

         maven { url "https://jitpack.io" }
    }
}


arapocket avatar Mar 14 '18 19:03 arapocket