Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Error getting location in NativeScript 5 #172

Closed

Description

@neumartin

Hi,

After upgrade NativeScript to version 5, I have this error:

Cannot enable the location service. Error: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbck;

My app.gradle is:

{
  "nativescript": {
    "id": "com.autocorp.autocorpapp",
    "tns-android": {
      "version": "5.0.0"
    }
  },
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "dependencies": {
    "moment": "^2.22.2",
    "nativescript-crossplatform-aes": "^1.0.3",
    "nativescript-directions": "^1.3.0",
    "nativescript-dom": "^2.0.2",
    "nativescript-geolocation": "^4.3.1",
    "nativescript-google-maps-sdk": "^2.6.1",
    "nativescript-loading-screen": "^1.0.6",
    "nativescript-phone": "^1.4.0",
    "nativescript-sqlite": "^2.2.3",
    "nativescript-theme-core": "^1.0.4",
    "nativescript-xml2js": "^0.5.2",
    "tns-core-modules": "^5.0.2"
  },
  "readme": "NativeScript Application",
  "devDependencies": {
    "nativescript-dev-webpack": "^0.17.0"
  }
}

Activity

  1. lukkystunt commented on Nov 12, 2018

    @lukkystunt

    @neumartin please any update on this, currently getting the same error.

  2. neumartin commented on Nov 12, 2018

    @neumartin
    Author

    @neumartin please any update on this, currently getting the same error.

    I just downgrade to 4, no solutions for now.

  3. fabiopolimeni commented on Nov 13, 2018

    @fabiopolimeni

    Getting the same error, geolocation doesn't seem to work anymore in NS 5

    Error: Cannot enable the location service. Error: java.lang.NoClassDefFoundError: com.google.android.gms.location.LocationRequest
    JS:     java.lang.Class.classForName(Native Method)
    JS:     java.lang.Class.forName(Class.java:324)
    JS:     java.lang.Class.forName(Class.java:285)
    JS:     com.tns.Runtime.getClassForName(Runtime.java:1036)
    JS:     com.tns.ClassResolver.resolveClass(ClassResolver.java:27)
    JS:     com.tns.Runtime.resolveClass(Runtime.java:604)
    JS:     com.tns.Runtime.callJSMethodNative(Native Method)
    JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
    JS:     com.tns.Runtime.callJSMethod(Runtime.java:983)
    JS:     com.tns.Runtime.callJSMethod(Runtime.java:967)
    JS:     com.tns.Runtime.callJSMethod(Runtime.java:959)
    JS:     com.tns.FragmentClass.onCreateView(FragmentClass.java:45)
    JS:     android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
    JS:     android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
    

    package.json

      "nativescript": {
        "id": "com.happee.app.mobile",
        "tns-ios": {
          "version": "4.2.0"
        },
        "tns-android": {
          "version": "5.0.0"
        }
      },
      "description": "NativeScript Application",
      "license": "SEE LICENSE IN <your-license-filename>",
      "repository": "<fill-your-repository-here>",
      "dependencies": {
        "nativescript-dom": "^2.0.2",
        "nativescript-geolocation": "^4.3.1",
        "nativescript-google-maps-sdk": "^2.6.1",
        "nativescript-pager": "^8.0.2",
        "nativescript-theme-core": "~1.0.4",
        "tns-core-modules": "^5.0.2",
        "tslib": "^1.9.3"
      },
      "devDependencies": {
        "eslint": "^5.9.0",
        "nativescript-dev-typescript": "^0.7.4",
        "nativescript-dev-webpack": "^0.18.0",
        "tslint": "^5.11.0",
        "typescript": "~2.7.2"
      },
    

    Someone who knows how to fix this, please have a look 🥇 :D

  4. changed the title [-]Error in NativeScript 5[/-] [+]Error getting location in NativeScript 5[/+] on Nov 14, 2018
  5. neumartin commented on Nov 14, 2018

    @neumartin
    Author

    I think that this is a bug, it is strange that we are few who had this issue and it is not labeled as a bug.
    @tbozhikov @nsndeck can you help us?

  6. Clifte commented on Nov 14, 2018

    @Clifte

    Same problem here.
    Error: Cannot enable the location service. Error: java.lang.NoClassDefFoundError: com.google.android.gms.location.LocationRequest

    package.json

    {
    "nativescript": {
    "id": "",
    "tns-ios": {
    "version": "5.0.0"
    },
    "tns-android": {
    "version": "5.0.0"
    }
    },
    "main": "app.js",
    "description": "NativeScript Application",
    "license": "SEE LICENSE IN ",
    "repository": "",
    "dependencies": {
    "moment": "^2.21.0",
    "nativescript-barcodescanner": "^2.7.4",
    "nativescript-camera": "^4.0.3",
    "nativescript-dom": "^2.0.0",
    "nativescript-fancyalert": "^1.2.0",
    "nativescript-geolocation": "^4.3.1",
    "nativescript-google-maps-sdk": "^2.5.0",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-orientation": "^2.2.0",
    "nativescript-platform-css": "^1.6.5",
    "nativescript-plugin-firebase": "^7.3.0",
    "nativescript-pro-ui": "3.1.4",
    "nativescript-speech-recognition": "^1.4.1",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-toast": "^1.4.6",
    "tns-core-modules": "^5.0.2"
    },
    "devDependencies": {
    "nativescript-dev-typescript": "~0.7.0",
    "nativescript-dev-webpack": "~0.18.0",
    "typescript": "^3.1.6"
    },
    "readme": "NativeScript Application"
    }

  7. annagrigoryan92 commented on Nov 14, 2018

    @annagrigoryan92

    I have the same problem, and after doing some testing I understood that the problem occurs after the installation of google-map sdk. When I delete it it works just fine. Anyone has any updates onthis?

  8. annagrigoryan92 commented on Nov 14, 2018

    @annagrigoryan92

    I fixed the problem by adding this file to App_Resources/Android

    file name: before-plugins.gradle
    content: android {
    // other stuff here

    project.ext {
    googlePlayServicesVersion = "15.0.1"
    }
    }

  9. fabiopolimeni commented on Nov 15, 2018

    @fabiopolimeni

    I fixed the problem by adding this file to App_Resources/Android

    file name: before-plugins.gradle
    content: android {
    // other stuff here

    project.ext {
    googlePlayServicesVersion = "15.0.1"
    }
    }

    @annadante, why version 15.0.1? And where did you find that information? Just in case I need to look up myself because of any mismatch. I used to have googlePlayServicesVersion = "+" which should force everything to the latest version.

    Thank you ;)

  10. annagrigoryan92 commented on Nov 15, 2018

    @annagrigoryan92

    I tried the "+" thing and it didn't work.

    The information was commented in the app.gradle file in Android folder :D

  11. DimitarTodorov commented on Nov 15, 2018

    @DimitarTodorov
    Contributor

    Hi @neumartin ,
    I've tested the plugin's demo and found that there is no issue with it. The problem that you observe is related to dependency which both nativescript-geolocation and nativescript-google-maps-sdk plugins are using. The googlePlayServicesVersion dependency should be used with same version for both plugins. So the solution of the issue, when building an app is to specify which version of the dependency should be used by both plugins. As suggested by @annadante you should add before-plugins.gradle file where the googlePlayServicesVersion should be specified:

    android {
        project.ext {
            googlePlayServicesVersion = "15.0.1" 
        }
    }
    
  12. neumartin commented on Nov 15, 2018

    @neumartin
    Author

    @DimitarTodorov thanks!, i will try.

  13. daniel-rfe commented on Nov 23, 2018

    @daniel-rfe

    I fixed the problem by adding this file to App_Resources/Android
    file name: before-plugins.gradle
    content: android {
    // other stuff here
    project.ext {
    googlePlayServicesVersion = "15.0.1"
    }
    }

    @annadante, why version 15.0.1? And where did you find that information? Just in case I need to look up myself because of any mismatch. I used to have googlePlayServicesVersion = "+" which should force everything to the latest version.

    Thank you ;)

    This worked for me too. However, I don't get why I had to create a new statement if I had previously pinned on app.graddle the "googlePlayServicesVersion" version to be used...

  14. dpdragnev commented on Nov 24, 2018

    @dpdragnev

    I tried the solution listed above, but now I am getting:

    The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
    

    Any suggestions?

  15. NickIliev commented on Nov 28, 2018

    @NickIliev

    @dpdragnev can you please post the package.json content so I can investigate your case (It is probably a conflict in the support library version as suggested by the error which is caused by a plugins requiring specific support version)

    Meanwhile, have you tried using before-plugins.gradle file to force a version

    app/App_Resources/Android/before-plugins.gradle

    android {  
      project.ext {
          googlePlayServicesVersion = "15.0.1"
      }
    } 
  16. dpdragnev commented on Nov 28, 2018

    @dpdragnev

    @NickIliev Here is my package.json:

    {
      "nativescript": {
        "id": "com.somecompany.someapp",
        "tns-ios": {
          "version": "4.2.4"
        },
        "tns-android": {
          "version": "5.0.0"
        }
      },
      "description": "My App",
      "license": "SEE LICENSE IN <your-license-filename>",
      "repository": "<fill-your-repository-here>",
      "dependencies": {
        "moment": "^2.22.2",
        "nativescript-geolocation": "^4.3.1",
        "nativescript-loading-indicator": "2.4.0",
        "nativescript-local-notifications": "3.1.0",
        "nativescript-plugin-firebase": "^7.3.0",
        "nativescript-theme-core": "~1.0.4",
        "tns-core-modules": "5.0.3"
      },
      "devDependencies": {
        "nativescript-dev-typescript": "~0.7.0",
        "nativescript-dev-webpack": "~0.15.0",
        "typescript": "~2.7.2"
      },
      "readme": "NativeScript Application"
    }
    

    I tried to add the before-plugins.gradle file and I cannot even build. I am getting a build error:

    Failed to capture fingerprint of input files for task ':app:checkDebugClasspath' property 'compileClasspath' during up-to-date check.
    > The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
    

    I am supposed to release this app to the play store next week. What would you suggest I do if we cannot find a solution to this issue? Should I downgrade from 5.0 to v 4.*?

    Thank you

  17. NickIliev commented on Nov 30, 2018

    @NickIliev

    @dpdragnev I am building a project with the exact same dependencies with no hassle. Looking at your error log the issue seems related to version mismatch of some Android libraries Update your Google Play Services to latest (details here)

  18. heese commented on Dec 5, 2018

    @heese

    Above (before-plugins.gradle) did not work for me but the approach described here: #156 (comment)

    Instead of + I used version 15.0.1

  19. bmargevicius commented on Dec 12, 2018

    @bmargevicius

    If you do the before-plugins.gradle method.
    You do not have to change app.gradle from googlePlayServicesVersion = "+".

  20. heese commented on Dec 12, 2018

    @heese

    This is what I tried first but it did not work for me. I have not investigated the reasons further as I found a good-enough solution.

  21. freddiandrew commented on Jan 21, 2019

    @freddiandrew

    @heese in my case ,when using this geolocation with firebase edit the following file

    node_modules/nativescript-geolocation/platform/android/include.gradle
    line 15 ...? project.googlePlayServicesVersion : "11.4.0"

    update to ? project.googlePlayServicesVersion : "16.+"

    i put the same value because booth firebase and geolocation use the same playService from google.

    project.ext {
    googlePlayServicesVersion = "16.+"
    }
    }

    i know that`s not best solution but it work for me..

  22. velval commented on Feb 12, 2019

    @velval

    @DimitarTodorov before-plugins.gradle solution works. Maybe worth changing the github documentation as I was trying to set googlePlayServicesVersion = "16.+" on the app.gradle file which is applied after the plugins configuration.

    applyBeforePluginGradleConfiguration()
    applyPluginGradleConfigurations()
    applyAppGradleConfiguration()
    
  23. aniruddhadas9 commented on Aug 5, 2019

    @aniruddhadas9

    Thanks @NickIliev @annadante for answers. it worked for me

    android {  
      project.ext {
          googlePlayServicesVersion = "15.0.1"
      }
    } 
    
  24. codeGV commented on Sep 10, 2020

    @codeGV

    I fixed the problem by adding this file to App_Resources/Android

    file name: before-plugins.gradle
    content: android {
    // other stuff here

    project.ext {
    googlePlayServicesVersion = "15.0.1"
    }
    }

    Cool, Thats work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions