Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Android 4.1 crashes with this plugin and latest play services #1051

Closed
mlabarca opened this issue Jul 5, 2016 · 13 comments
Closed

Android 4.1 crashes with this plugin and latest play services #1051

mlabarca opened this issue Jul 5, 2016 · 13 comments

Comments

@mlabarca
Copy link
Contributor

mlabarca commented Jul 5, 2016

Expected Behaviour

App executes normally without crashes.

Actual Behaviour

Push actually registers successfully and I get a token, but for some reason my app crashes in an unreleated part of my app. (Login) When the plugin is removed, and actually replaced with the deprecated version (com.phonegap.plugins.pushplugin) the app works normally with push notifications and all.

Reproduce Scenario (including but not limited to)

Run an app with this plugin (even without calling init() ) in a device with the specs below.

Steps to Reproduce

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 4.1.2

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Samsung Galaxy s3 Mini. It works perfectly in an LG G3 stylus (android 5) and a Moto X play (Android 6)

Cordova CLI version and cordova platform version

cordova --version:       cli-5.2.0                            
cordova platform version android: cordova android 4.1.1                     

Plugin version

cordova plugin version | grep phonegap-plugin-push   # e.g. 1.5.3

Latest version.

Sample Push Data Payload

Sample Code that illustrates the problem

Logs taken while reproducing problem

Specific part of the log with the crash:

07-05 16:55:54.039: E/dalvikvm(5687): Class lookup Landroid/webkit/WebResourceResponse; attempted with exception pending
07-05 16:55:54.039: W/dalvikvm(5687): Pending exception is:
07-05 16:55:54.039: I/dalvikvm(5687): java.lang.NullPointerException:
07-05 16:55:54.039: I/dalvikvm(5687):   at android.content.res.AssetManager.openAsset(Native Method)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.content.res.AssetManager.open(AssetManager.java:315)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.BrowserFrame.inputStreamForAndroidResource(BrowserFrame.java:860)

Full logcat:
https://gist.github.com/mlabarca/2fa8688c74e4b615793bd64c1d3836a9

Notes:

At first I though this was also related to #909, But play services in the device in question is at the most recent version (9.2.56). I also attempted re-applying
this commit in my fork : 2fecb9c to lock down the services requirement(both in plugin.xml and push.gradle) but that didn't work either. I'm starting to think this is a separate issue with something else bundled with this plugin.

I'm seeing this building with phonegap build and also in cli.

@macdonst
Copy link
Member

macdonst commented Jul 6, 2016

@mlabarca hey, I took a look at your stack trace:

07-05 16:55:54.039: I/dalvikvm(5687): java.lang.NullPointerException:
07-05 16:55:54.039: I/dalvikvm(5687):   at android.content.res.AssetManager.openAsset(Native Method)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.content.res.AssetManager.open(AssetManager.java:315)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.BrowserFrame.inputStreamForAndroidResource(BrowserFrame.java:860)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.BrowserFrame.shouldInterceptRequest(BrowserFrame.java:951)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.os.Looper.loop(Looper.java:137)
07-05 16:55:54.039: I/dalvikvm(5687):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1127)
07-05 16:55:54.039: I/dalvikvm(5687):   at java.lang.Thread.run(Thread.java:856)

and nowhere in there does a part of the Push Plugin java code get executed. If you comment out the call to init and rebuild your app does it still crash?

@mlabarca
Copy link
Contributor Author

mlabarca commented Jul 6, 2016

Unfortunately, yeah. Even with init 'on' it registers without issues and i
see the token stored in device storage, problem comes after a login action
that is unrelated. It seems it's a problem with a dependency or something.
I'll recheck and try to build and run this tomorrow with much earlier
version (say, 1.5) to narrow it down more.

@macdonst
Copy link
Member

macdonst commented Jul 6, 2016

@mlabarca I think what you should concentrate on is looking for spots in your code that attempt to load files from the assets folder on Android. That is what the stack trace indicates to me.

@mlabarca
Copy link
Contributor Author

mlabarca commented Jul 6, 2016

@macdonst I thought the same at first, but it doesn't really explain why it works with more recent android devices and when removing the plugin.
Anyways, after spending some time trying out versions, no crashes occur in the device in question when using version 1.3.0; crash happens with plugin version 1.4.0 onwards. I'll take a look at the changelog and see what I can find.

@mlabarca
Copy link
Contributor Author

mlabarca commented Jul 6, 2016

@macdonst hmm Well from this commit a69b596 version 1.4.0 changed a lot of stuff from the way dependencies are handled. Any ideas? are there other libraries that have to be installed in the device besides the latest play services version or something not being added properly by phonegap build?

@macdonst
Copy link
Member

macdonst commented Jul 6, 2016

@mlabarca first thing I'd do would be to delete your projects platforms/android directory then re-add the android platform cordova platform add android and see if you can reproduce it.

Can you send me what your init code looks like?

@mlabarca
Copy link
Contributor Author

mlabarca commented Jul 7, 2016

@macdonst Sorry for the delay.

  1. This tests were done using phonegap build. If I understand pgb correctly anything on the platforms folder shouldn't affect it right? I did do one test locally, I did have to rebuild the android platform anyways since I had the old deprecated push plugin.
  2. First, the init code itself:
    var initPush = function(){
      var androidParams = {senderID: zimplepr.config.pushNotification.android.senderID, clearBadge: true};
      var iosParams =  {'badge': 'true', 'sound': 'true', 'alert': 'true', clearBadge: true};
      return PushNotification.init({android: androidParams, ios: iosParams});
    };

and when is it called:

cordovaService.then(function () {
        var push = initPush();
        push.on('registration', function(notification) {
          var token = notification.registrationId;
          handleToken(token, platform) // stores device token on device to be sent later to our server
        });

        push.on('notification', function(data){
           // notification Callback
        });
}

and cordova service returns a promise that resolves when the device is ready like this:

function($window, $document, $q){

    var deferred = $q.defer(),
    var resolved = false,
    var promise =  deferred.promise;

    $document[0].addEventListener('deviceready', function(){
      resolved = true;
      deferred.resolve($window.cordova);
    }, false);

    return promise;
  });

This doesn't seem the issue to me since like I've said before, I get the token without problems and I haven't had any issues in recent versions and the app initializes. It's just on an unrelated login action after login credential are input by the user where I send the token to the server that the crash happens from version 1.4 onwards. Hope this helps at least :/

@macdonst
Copy link
Member

macdonst commented Jul 7, 2016

@mlabarca there is nothing in the code that you posted that has anything to do with loading anything from the assets folder so I feel as if the push plugin is not to blame here.

When you go to the login screen are you trying to load something from assets that a) does not exist or b) has a special character like : in it? Apparently having a : in the URL is a problem.

https://code.google.com/p/android/issues/detail?id=46721

@mlabarca
Copy link
Contributor Author

mlabarca commented Jul 8, 2016

@macdonst Something I've just noticed (not sure if it's related) comparing tokens with recent and old plugin versions. For the same phone in the old deprecated plugin I'm receiving a token like APA91bHiZJoSgvS2EJvoOCjl0UzGUBInV6OkDiGYtQ6vPCZnegyv.... but from this plugin in more recent phones i receive **chLNI95DAOo:**APA91bHiZJoSgvS2EJvoOCjl0UzGUBInV6OkDiGYt.... Isn't this something that happens when firing the plugin before a device ready event? notifications do work, though.

@macdonst
Copy link
Member

macdonst commented Jul 8, 2016

@mlabarca the old plugin used the gcm.jar to get the registration ID. This plugin uses updated libraries gcm and google instance ID. That is why the registration ID looks a bit different. You are getting it in the correct format.

@macdonst
Copy link
Member

macdonst commented Sep 9, 2016

Closing, inactivity

@macdonst macdonst closed this as completed Sep 9, 2016
@mlabarca
Copy link
Contributor Author

To anyone who is lost in a similar issue and uses angular, this was not a problem with the push plugin per se. GCM tokens can sometimes be in the form of '**chLNI95DAOo:**APA91bHiZJoS...'. This small colon that should be present seems to be generated in mostly android versions (Hence why it don't see the issue happen in android >4.4), when sent in an ajax request with the wrong encoding, crashed the app since it interpreted it as accessing a local non-existent template instead of the ajax request. Simply encoding that token with encodeURIcomponent in an $http interceptor and parsing it at the server fixed the issue. So sorry for the inconvenience 😞

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants