ably / ably-java

Java, Android, Clojure and Scala client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
85 stars 40 forks source link

Crash on Android with api level 18 and below #332

Closed liuzhen2008 closed 7 years ago

liuzhen2008 commented 7 years ago

My app installed on a android jelly bean phone would crash immediately on launch.

It looks like the ably SDK is using "StandardCharset" And it is only introduced in API level 19. https://developer.android.com/reference/java/nio/charset/StandardCharsets.html

This is different from the doc saying it supports API 14.

 FATAL EXCEPTION: Thread-636
java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at io.ably.lib.types.ProtocolSerializer.writeJSON(ProtocolSerializer.java:55)
at io.ably.lib.transport.ConnectionManager.onMessage(ConnectionManager.java:445)
at io.ably.lib.transport.WebSocketTransport$WsClient.onMessage(WebSocketTransport.java:164)
at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:253)
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:381)
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:158)
at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:185)
at java.lang.Thread.run(Thread.java:841)
mattheworiordan commented 7 years ago

@liuzhen2008 thanks for reporting this and sorry for the inconvenience.

Fortunately this looks like the issue can be fixed quite trivially by replacing:

Serialisation.gson.toJson(message).getBytes(StandardCharsets.UTF_8);

with:

Serialisation.gson.toJson(message).getBytes(Charset.forName("UTF-8"));

Reference https://stackoverflow.com/questions/32102166/standardcharsets-utf-8-on-lower-api-lower-than-19

We'll see if we can get a fix out for it ASAP, unless you want to do a PR perhaps to fix it before one of our engineers gets the time to do a fix? Looks like only 4 lines need changing

liuzhen2008 commented 7 years ago

https://github.com/ably/ably-java/pull/333

liuzhen2008 commented 7 years ago

@mattheworiordan Do you know what I can do so that I can include my own fork in my current project?

I tried to simply include this line compile 'com.github.liuzhen2008:ably-android:v1.0.1' into my dependencies, but it looks like it is not as simple as that. (I got this error instead)

Error:Could not GET 'https://jitpack.io/com/github/liuzhen2008/ably-android/v1.0.1/ably-android-v1.0.1.pom'. Received status code 401 from server: Unauthorized
Enable Gradle 'offline mode' and sync project

Do you have any idea how I can include the fix quickly?

liuzhen2008 commented 7 years ago

@mattheworiordan I see the PR has been merged. How do I include the latest master build?

paddybyers commented 7 years ago

I see the PR has been merged. How do I include the latest master build?

I'll be doing a release shortly. Unfortunately for Android we don't have a build option to build a full jar from source so it's not easy for you to run the latest version until we make a release.

paddybyers commented 7 years ago

This is now released as https://bintray.com/ably-io/ably/ably-android/1.0.1

maurylm commented 4 years ago

Hi, I have the same issue with the lastest version 1.2.1 on android.