[TIMOB-26037] Hyperloop: Accessing internal WebSocket library
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2019-07-30T01:09:12.000+0000 |
Affected Version/s | Release 7.1.1 |
Fix Version/s | n/a |
Components | n/a |
Labels | android, engTriage, hyperloop, websocket |
Reporter | Michael Gangolf |
Assignee | Joshua Quick |
Created | 2018-05-08T17:02:01.000+0000 |
Updated | 2020-03-19T00:52:19.000+0000 |
Description
Titanium is shipping a
java_websocket.jar
in /linux/7.1.1.GA/android/
which I can use in a normal Android module by just importing it with import org.java_websocket.client.WebSocketClient;
. No need to put the jar into my project folder.
When trying the same with Hyperloop I always get the error, that the module is not found. When placing the jar into the project folder it complains about duplicate classes.
Is there a way to access the libraries inside the Android folder using Hyperloop?
Titanium SDK 7.1.1.GA
Devs can use our "titanium-socketio" module for websocket support. https://github.com/appcelerator-modules/titanium-socketio
[~ahutton] we've tried to connect to a Websocket server (not a socket.io server!) with the Socketio module today and weren't able to do that because of
xhr poll
errors. I didn't try it but I guess the same error as in the description would appear for other modules inside the SDKs library folder (so you can't use exifinterface.jar or a support library in HL?)[~michael], hyperloop currently does not support referencing Titanium's core JARs and the JARs it directly includes. It's not part of hyperloop's lookup path. And adding the WebSocket JAR to your "modules" directory will cause a build failure due to Java class collision (renaming the JAR file won't solve this). I think your only option is to make a native module and leverage the WebSocket JAR that Titanium already includes. Ideally, hyperloop should be changed to lookup Titanium's core JARs as well. I don't think there is any technical reason why this limitation should exist. But I don't see us doing this in the near future though. Side Note: Titanium uses web sockets for debugging.
Alternatively, you can use a command line tool to change the package names of all Java classes within the WebSocket JAR and include that in your "modules" directory. That would work, but it's kind of a slimy hack. https://stackoverflow.com/questions/13746737/hand-edit-a-jar-to-change-package-names That said, Google has a tool that transitions JARs from the old Google Support libraries to the new AndroidX libraries. For example, their tool change references from
android.support.v7.app.AppCompatActivity
toandroidx.appcompat.app.AppCompatActivity
. So, Google sanctions hacks like this. Not quite the same for what I'm suggesting above, but if you need any justification, here it is. :P https://developer.android.com/jetpack/androidx/migrateThanks [~jquick] for all the details! I think the module will be the easiest way :)
[~michael], I wrote this up as a feature request here: [TIMOB-27297]
[~michael], as of Titanium 9.0.0 you can do this now. I recommend that you copy our "titanium.socketio" module's "build.gradle" via the link below and copy it to your project's
./platform/android
directory. https://github.com/appcelerator-modules/titanium-socketio/blob/master/android/build.gradle This will allow hyperloop to access the Java classes you see in the below repo. https://github.com/socketio/socket.io-client-java