Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.xml parsing breaks on cordova-android 6.4.0 #206

Closed
davidgovea opened this issue Dec 29, 2017 · 8 comments
Closed

config.xml parsing breaks on cordova-android 6.4.0 #206

davidgovea opened this issue Dec 29, 2017 · 8 comments

Comments

@davidgovea
Copy link
Contributor

Hi UA team,

Just tracked down a weird one.
I was failing to receive push messages on Android, but channel registration and rich push messages were coming in fine.

Inspecting logcat showed INVALID_SENDER gcm registration errors (will add log in comment)

This was weird, because previous app versions were still working, and the project setup had not changed.

Turns out

the issue is related to cordova-android version 6.4.0.
Rather than parsing a GCM sender ID as "123456789012", the pluginConfig.getString() call is returning something like 1.23456765E11. (note the float precision skew, hah)

This can be replicated on the sample app, by simply updating the android platform version from 6.3.0 to 6.4.0. Not sure if all GCM sender IDs are numeric, but this doesn't happen if there are any alphanumeric characters in the sender ID.

@davidgovea
Copy link
Contributor Author

From parse config log:
Found com.urbanairship.gcm_sender in config.xml with value: 3.89833064E11

Log from example app:

12-29 15:52:09.343 30003 30140 E Test - UALib: Push registration failed.
12-29 15:52:09.343 30003 30140 E Test - UALib: com.urbanairship.push.PushProvider$RegistrationException: GCM registration failed.
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.push.gcm.GcmPushProvider.getRegistrationToken(GcmPushProvider.java:55)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.push.PushManagerJobHandler.onUpdatePushRegistration(PushManagerJobHandler.java:178)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.push.PushManagerJobHandler.performJob(PushManagerJobHandler.java:118)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.push.PushManager.onPerformJob(PushManager.java:386)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.job.Job$1.run(Job.java:83)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at java.lang.Thread.run(Thread.java:764)
12-29 15:52:09.343 30003 30140 E Test - UALib: Caused by: java.io.IOException: INVALID_SENDER
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.google.android.gms.iid.zzl.zzb(Unknown Source:649)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.google.android.gms.iid.zzl.zza(Unknown Source:0)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.google.android.gms.iid.InstanceID.zzb(Unknown Source:65)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.google.android.gms.iid.InstanceID.getToken(Unknown Source:134)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	at com.urbanairship.push.gcm.GcmPushProvider.getRegistrationToken(GcmPushProvider.java:47)
12-29 15:52:09.343 30003 30140 E Test - UALib: 	... 7 more
12-29 15:52:09.344 30003 30140 V Test - UALib: Job - Finished: JobInfo{action=ACTION_UPDATE_PUSH_REGISTRATION, id=4, extras='{}', airshipComponentName='com.urbanairship.push.PushManager', isNetworkAccessRequired=false, initialDelay=0, persistent=false} with result: 1

@davidgovea
Copy link
Contributor Author

davidgovea commented Dec 29, 2017

Found a workaround, but the situation is pretty unfortunate.

cordova-android 6.4.0 didn't introduce much that was new, aside from moving to the Android Studio 3.0 gradle setup.

Apparently, the XMLPullParser changed somewhere along the way:
Here is the only related issue I could find: Android's XMLPullParser getAttributeValue is removing leading zeros from string

Number-like strings are now treated differently :(

There isn't much more the UA library can do -- there is no way to request a string from the XMLPullParser -- it seems to be mangled before we ever get to it.

I tried setting android.enableAapt2=false in the gradle properties, but the problem persisted. Apparently not related to the new AAPT2 resource system. Edit, see next comment

I also tried various xml namespace type hints, but that was just flailing.

So, workaround?

It's nasty.

<platform name="android">
    <preference name="com.urbanairship.gcm_sender" value="123456789012\" /> <!-- added trailing backslash slash -->
</platform>
<!-- Normal for iOS -->
<preference name="com.urbanairship.gcm_sender" value="123456789012" />

This "just happens to work" with the new XML parser, but it is NOT compatible with iOS or the previous cordova-android versions. So it must be inside a platform tag, and is obviously not a great solution.

Well, uh

This will need to be addressed going forward toward cordova-android@7 and beyond. Hopefully there's some bit of documentation I missed, and this is easy to handle properly.

Thanks for reading!

@davidgovea
Copy link
Contributor Author

Better workaround: Disabling AAPT2

So, actually, creating a platforms/android/gradle.properties file with android.enableAapt2=false fixes the issue. Before, I was adding the option to project.properties - whoops.

Unfortunately I don't see a built-in way for plugins to edit this file, but I can now confirm that AAPT2 is causing this xml parsing difference, just like in the SO thread I linked above

@davidgovea
Copy link
Contributor Author

Made a quick plugin: https://github.com/runtrizapps/cordova-android-disable-aapt2

Works on my box™

@rlepinski
Copy link
Contributor

@davidgovea Awesome work. Definitely looks like an AAPT2 bug, not sure how we are going to work around it right now. Ill report back once we have a solution.

@rlepinski
Copy link
Contributor

Google issue: https://issuetracker.google.com/issues/69347762

Long term solution we are looking into allowing calling takeOff from JS, however we are running into some migration issues, so its probably not going to happen in the next release. For the short term, we are going to allow prefixing the sender ID with sender:, it's gross but it works. We will also recommend using your plugin instead of prefixing.

@rlepinski
Copy link
Contributor

Released 6.9.3 with the changes and README updates.

@davidgovea
Copy link
Contributor Author

Thank you!

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

No branches or pull requests

2 participants