[TIMOB-28149] Android: App builds fail if it includes "Java-WebSocket" library
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-11-30T19:10:10.000+0000 |
Affected Version/s | Release 9.0.0 |
Fix Version/s | Release 9.3.0 |
Components | Android |
Labels | android, build, gradle, library |
Reporter | Hans Knöchel |
Assignee | Joshua Quick |
Created | 2020-09-22T14:43:14.000+0000 |
Updated | 2020-11-30T19:10:10.000+0000 |
Description
*Summary:*
If an app includes the "Java-WebSocket" library via gradle (or a module that references it via gradle), then it will fail to build.
*Steps to reproduce:*
Add the below "build.gradle" to project folder:
Create a "Classic" Titanium app project.
Add the below "build.gradle" to project folder: ./platform/android
Build for Android.
./platform/android/build.gradle
dependencies {
implementation 'org.java-websocket:Java-WebSocket:1.5.1'
}
*Result:*
The following build failure will occur...
[ERROR] [GRADLE] java.lang.RuntimeException: Duplicate class org.java_websocket.AbstractWebSocket found in modules jetified-Java-WebSocket-1.5.1.jar (org.java-websocket:Java-WebSocket:1.5.1) and jetified-titanium-9.2.0-runtime.jar (org.appcelerator:titanium:9.2.0)
*Cause:*
Titanium builds with a local "java_websocket.jar" below. It's used by V8 for debugging. We need to remove th JAR and instead reference the library via gradle.
https://github.com/appcelerator/titanium_mobile/tree/master/android/runtime/v8/lib
*Work-Around:*
Add the following "build.gradle" to the app project's ./platform/android
folder. It will exclude websocket library references from the gradle build to avoid collision with Titanium's local JAR. Although, once we fix this issue, you'll need to remove the below.
configurations {
all {
exclude group: 'org.java-websocket', module: 'Java-WebSocket'
}
}
[~hknoechel], our "ti.socketio" module was updated in Titanium 9.0.0 to stop using local JARs and reference this library via gradle instead. (We did the same with all of our other modules in 9.0.0 as well.) https://github.com/appcelerator-modules/titanium-socketio/pull/25 You must be using a 3rd party module that's bundling its own local websocket JAR ("Java-WebSocket-1.5.1.jar"?) and that's the cause of the collision. It needs to be updated to reference it in the "build.gradle" similar to how we're doing it below. https://github.com/appcelerator-modules/titanium-socketio/blob/master/android/build.gradle
We do not use Ti.SocketIO, that's why I'm wondering
Hold on. You're right. Titanium has a local web socket JAR used by V8 here... https://github.com/appcelerator/titanium_mobile/tree/master/android/runtime/v8/lib I can reproduce the issue you're seeing by setting up a Titanium app with the following "build.gradle" file.
So, I still think you have a module which is referencing the websocket library, but that module is likely indirectly referencing websockets the "right" way via gradle. It's Titanium that needs to change to reference it via gradle as well. For now, you can work-around the issue by adding the following to your app project's "build.gradle". This tells the build system to exclude a websocket library gradle dependency. Although once we update Titanium to reference it via gradle too, you'll need to remove the below.
Thanks for bringing this up.
Thanks Josh! I kept the old version (as an .aar) for now, but it would be great to update it during one of the next releases :)
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12119
FR passed. Waiting for Jenkins.
Closing.