NativeScript / nativescript-geolocation

Geolocation plugin to use for getting current location, monitor movement, etc
Apache License 2.0
139 stars 76 forks source link

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

Closed bbetter closed 6 years ago

bbetter commented 6 years ago

Android

lini commented 6 years ago

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

bbetter commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Using 11.8.0 yields same result, any pointers on this?

project.ext { googlePlayServicesVersion = "11.8.0" }

bbetter commented 6 years ago

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

ghost commented 6 years ago

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 commented 6 years ago
_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 commented 6 years ago

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:

"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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

any updates on this?

DimitarTachev commented 6 years ago

Hi @rajd90,

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

rajd90 commented 6 years ago

I've just tried removing and adding the platforms folder but i still get an error. What else can I try? Is there an eta on when the issue will be resolved?

On Fri, 2 Mar 2018 at 08:17 Dimitar Tachev notifications@github.com wrote:

Hi @rajd90 https://github.com/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 https://github.com/NativeScript/nativescript-cli/issues/3354. Meanwhile, as a workaround, you could remove your platforms folder after installing a new plugin depending on Google Play Services.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NativeScript/nativescript-geolocation/issues/93#issuecomment-369852596, or mute the thread https://github.com/notifications/unsubscribe-auth/AhFHJ9qQflgraZYYZ95nIpbeIUrt6cVQks5taQADgaJpZM4Q-bwS .

DimitarTachev commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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.

luishcastroc commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

abhayastudios commented 6 years ago

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 commented 6 years ago

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?