Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28149] Android: App builds fail if it includes "Java-WebSocket" library

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-11-30T19:10:10.000+0000
Affected Version/sRelease 9.0.0
Fix Version/sRelease 9.3.0
ComponentsAndroid
Labelsandroid, build, gradle, library
ReporterHans Knöchel
AssigneeJoshua Quick
Created2020-09-22T14:43:14.000+0000
Updated2020-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:*

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'
	}
}

Comments

  1. Joshua Quick 2020-09-22

    [~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
  2. Hans Knöchel 2020-09-22

    We do not use Ti.SocketIO, that's why I'm wondering
  3. Joshua Quick 2020-09-22

    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.
       dependencies {
       	implementation 'org.java-websocket:Java-WebSocket:1.5.1'
       }
       
    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.
       configurations {
       	all {
       		exclude group: 'org.java-websocket', module: 'Java-WebSocket'
       	}
       }
       
    Thanks for bringing this up.
  4. Hans Knöchel 2020-09-22

    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 :)
  5. Joshua Quick 2020-09-22

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12119
  6. Sohail Saddique 2020-10-07

    FR passed. Waiting for Jenkins.
  7. Lokesh Choudhary 2020-11-30

    Closing.

JSON Source