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

S: ERROR Error: Uncaught (in promise): TypeError: ex.getStatusCode is not a function #93

Closed
bbetter opened this issue Dec 12, 2017 · 23 comments
Assignees

Comments

@bbetter
Copy link

bbetter commented Dec 12, 2017

Android

@lini
Copy link
Contributor

lini commented Dec 15, 2017

Please, give us a bit more information about this issue:

  • Do you reproduce it with the demo app? If yes, give us the steps you make.
  • Does it happen on a real device or an emulator?
  • Which version of the NativeScript CLI and the nativescript-geolocation plugin are you using?

@bbetter
Copy link
Author

bbetter commented Dec 18, 2017

  1. I can try it in few hours
  2. it does happen both on emulator and on real device
    emulator is latest Pixel
    and real device is Samsugn Galaxy s8+
  3. Both are latest if I remember correctly, but i'll double check

@Svettis2k
Copy link

This happened to me when I had conflicting googlePlayServicesVersion in the include.gradle of nativescript-geolocation and nativescript-google-maps-sdk plugins. I set both to default to "11.4.0" and the error disappeared. Not sure if OP's problem is due to the same problem, but it might worth checking out.

@johnespn
Copy link

johnespn commented Jan 9, 2018

Using 11.8.0 yields same result, any pointers on this?

project.ext {
googlePlayServicesVersion = "11.8.0"
}

@bbetter
Copy link
Author

bbetter commented Jan 15, 2018

I've been off for few weeks with this task, would appreciate any pointers on this as well
@lini @johnespn @Svettis2k

@ghost
Copy link

ghost commented Jan 15, 2018

Hi,

I had the same problem, you have to modify
yourProject\node_modules\nativescript-geolocation\platforms\android\include.gradle in dependencies : def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : "11.4.0"
compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
to
def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : '+'
compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"

after you use "tns build android".

@ryannuijen
Copy link

ryannuijen commented Jan 17, 2018

_isLocationServiceEnabled().then(function () {
     resolve();
 }, function (ex) {
    var statusCode = ex.getStatusCode();
    ...
}

Same here with Play Services 11.8.0. The error handler is returning TypeError: com.google.android.gms.location.LocationRequest is not a constructor

@rajd90
Copy link

rajd90 commented Jan 20, 2018

I'm getting the same error....

Which platform(s) does your issue occur on?

Android and real device - google pixel
Haven't yet tried iOS.

Please, provide the following version numbers that your issue occurs with:

  • CLI: 3.4.0
  • Cross-platform modules: 3.4.0
  • Runtime(s): 3.4.0
  • Plugin(s):
"dependencies": {
    "@angular/animations": "~4.4.1",
    "@angular/common": "~4.4.1",
    "@angular/compiler": "~4.4.1",
    "@angular/core": "~4.4.1",
    "@angular/forms": "~4.4.1",
    "@angular/http": "~4.4.1",
    "@angular/platform-browser": "~4.4.1",
    "@angular/router": "~4.4.1",
    "nativescript-angular": "~4.4.1",
    "nativescript-couchbase": "^1.0.18",
    "nativescript-geolocation": "^4.2.2",
    "nativescript-google-maps-sdk": "^2.3.2",
    "nativescript-google-places": "0.0.3",
    "nativescript-iqkeyboardmanager": "^1.1.0",
    "nativescript-material-icons": "^1.0.3",
    "nativescript-ng2-fonticon": "^1.3.4",
    "nativescript-pro-ui": "^3.1.4",
    "nativescript-theme-core": "~1.0.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.4.2",
    "tns-core-modules": "^3.4.0",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.5.0",
    "tns-platform-declarations": "^3.4.0",
    "typescript": "~2.4.2"
  }

Please, tell us how to recreate the issue in as much detail as possible.

Open the app. Get the following error straight away...

JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: ERROR Error: Uncaught (in promise): TypeError: ex.getStatusCode is not a function
JS: TypeError: ex.getStatusCode is not a function
JS: at ...../files/app/tns_modules/nativescript-geolocation/geolocation.js:156:41

Is there any code involved?

Call the following function from the constructor of the main component

private enableLocation() { 
        geolocation.isEnabled().then(function (isEnabled) {
            if (!isEnabled) {
                geolocation.enableLocationRequest().then(function () {
                }, function (e) {
                    console.log("Error: " + (e.message || e));
                });
            }
        }, function (e) {
            console.log("Error: " + (e.message || e));
        });
    }

@DimitarTachev
Copy link
Contributor

DimitarTachev commented Jan 23, 2018

Hi guys, we found the issue with the exception handling in enableLocationRequest.

It was fixed in PR #105 and released in version 4.2.3 of the plugin.

@rajd90
Copy link

rajd90 commented Jan 28, 2018

I'm still having trouble. I get an "Error: Cannot enable the location service" despite seeing location permissions for the app are enabled in the Android settings.

@DimitarTachev
Copy link
Contributor

Hi @rajd90,

It seems that you are getting some unexpected exception on the location service check which is not reproducible on our side and in this way, you are going through the devices without a location service flow.

Could you debug and check the exception (ex) in your ./node_modules/nativescript-geolocation/geolocation.android.js file on line 168 (reject(new Error("Cannot enable the location service"));) or just add a console log with the exception (ex) just before the reject call and update us back with the exception message?

You could also check if the exception is reproducible on other devices or emulators and if yes, a sample application reproducing this behavior will be highly appreciated.

@DimitarTachev
Copy link
Contributor

Hi guys,

We were able to reproduce such exception by using the plugin along with the Firebase one. The inner exception is LocationRequest is not a constructor.

We are still investigating the issue but as a workaround, you could delete your platforms folder and rebuild your app.

We will update you back when we have further details.

@rajd90
Copy link

rajd90 commented Mar 1, 2018

any updates on this?

@DimitarTachev
Copy link
Contributor

Hi @rajd90,

We found the reason for this exception and it's now logged in the CLI repo. You could track the status of NativeScript/nativescript-cli#3354. Meanwhile, as a workaround, you could remove your platforms folder after installing a new plugin depending on Google Play Services.

@rajd90
Copy link

rajd90 commented Mar 10, 2018 via email

@DimitarTachev
Copy link
Contributor

DimitarTachev commented Mar 13, 2018

@rajd90 This issue is related to the 'TypeError: ex.getStatusCode is not a function' error.

Please provide us with a sample application if you still get the same error after removing the platforms folder or open a new issue if you are getting a different exception.

@rajd90
Copy link

rajd90 commented Apr 14, 2018

@DimitarTachev .....I have tried removing and add the platform, as well as removing and adding the plugin. I think the original error is gone, but I'm now getting the following error:

Error: Cannot enable the location service. TypeError: com.google.android.gms.location.LocationRequest is not a constructor

I've also tried changing the google play services version in the app.gradle file but no luck.

@DimitarTachev
Copy link
Contributor

Hi @rajd90, if setting the googlePlayServicesVersion following this section, removing your platform folder and rebuilding your app doesn't help, please send us a sample app reproducing the exception.

Also, make sure you are using one of the the latest versions of the NativeScript Android runtime and NativeScript CLI.

@ghost ghost removed the question label Jul 6, 2018
@luishcastroc
Copy link

I have pretty much the same issue, when I try to tns run android I get this error (I already tried in iOS with no issues so far)

ERROR Error: Uncaught (in promise): Error: Cannot enable the location service. Error: java.lang.NoClassDefFoundError: com.google.android.gms.location.LocationRequest

@lini
Copy link
Contributor

lini commented Jul 17, 2018

Check if some of the above answers can help you - removing platforms directory, setting googlePlayServicesVersion in your application's app.gralde file. The error is probably caused because of a conflict with another plugin in the app that uses a Google Play Services version different from the one used by the geolocation plugin (11.4.0 in the latest release). If the problem persists, please open a new issue and give us some more information about your configuration or send a sample app that can be used to reproduce the error.

@luishcastroc
Copy link

thanks that made the trick for me (modifying the dependency for the proper google play services version)

@abhayastudios
Copy link

abhayastudios commented Jul 25, 2018

I have the same now after removing the following from my app.gradle:

  // required to make the firebase and geolocation plugins play nice together
  // see: https://github.com/NativeScript/nativescript-geolocation/issues/81
  project.ext {
    googlePlayServicesVersion = "12.0.1"
    supportVersion = "26.0.0"
  }

The problem is that the latest versions of nativescript-plugin-firebase require Google Play Services v15: googlePlayServicesVersion set too low, please update to at least 15.0.0.

@NickIliev please re-open this issue. It needs to be fixed to be able to be used in recent versions of Google Play Services.

Please advise!

@abhayastudios
Copy link

abhayastudios commented Jul 25, 2018

I found that this line of code of this project sets the default googlePlayServicesVersion to 11.4.0 unless the project sets another version.

I was able to resolve my conflict with nativescript-plugin-firebase, but simply setting the googlePlayServicesVersion version to the same one as required by nativescript-plugin-firebase as follows in my app.gradle:

project.ext {
  googlePlayServicesVersion = "15.0.0"
}

Is there not a better way of resolving plugins dependencies?

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

No branches or pull requests