hoijui / JavaOSC

OSC content format/"protocol" library for JVM languages
http://www.illposed.com/software/javaosc.html
BSD 3-Clause "New" or "Revised" License
157 stars 44 forks source link

java.awt.color on android #60

Closed JellevanAbbema closed 2 years ago

JellevanAbbema commented 3 years ago

I am having this issue on windows and on android using a part of this library. I am only using it to create OSC Messages with arguments and to parse it to a byteBuffer so I can send it via my own protocol.

Error log on android: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Color; at com.illposed.osc.argument.handler.AwtColorArgumentHandler.getJavaClass(AwtColorArgumentHandler.java:43) at com.illposed.osc.OSCSerializer.<init>(OSCSerializer.java:101) at com.illposed.osc.OSCSerializerAndParserBuilder.buildSerializer(OSCSerializerAndParserBuilder.java:64)

EDIT: So when I opened this issue I was in a hurry, but after looking at it a couple hours later I think I found the problem, kind of. The issue is with the java.awt.color library, which is not supported on android. I found some older issues and fixes (#43, #49), so that should mean this problem souldn't exist. But apperantly it does with the latest version (0.8) of this library, maybe something slipt in?

danielskeenan commented 3 years ago

Having the same problem using both 0.8 and the current commit (e868db3). For what it's worth, I'm developing for Android Wear OS, which has an even more limited set of libraries available. Here's a stack trace:

    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Color;
        at com.illposed.osc.argument.handler.AwtColorArgumentHandler.getJavaClass(AwtColorArgumentHandler.java:39)
        at com.illposed.osc.OSCSerializer.<init>(OSCSerializer.java:97)
        at com.illposed.osc.OSCSerializerAndParserBuilder.buildSerializer(OSCSerializerAndParserBuilder.java:60)
        at com.illposed.osc.transport.channel.OSCDatagramChannel.send(OSCDatagramChannel.java:96)
        at com.illposed.osc.transport.udp.UDPTransport.send(UDPTransport.java:134)
        at com.illposed.osc.transport.OSCPortOut.send(OSCPortOut.java:119)
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.send(EosConsoleComm.kt:47)
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.send$default(EosConsoleComm.kt:45)
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.discover(EosConsoleComm.kt:40)
        at org.dankeenan.wearrfr.consolelist.ConsoleListViewModel$discover$1.invokeSuspend(ConsoleListViewModel.kt:49)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6680)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Color" on path: DexPathList[[zip file "/system/framework/com.google.android.wearable.jar", zip file "/data/app/org.dankeenan.wearrfr-OVZ-31TN_FnOlKXIHEwH0Q==/base.apk"],nativeLibraryDirectories=[/data/app/org.dankeenan.wearrfr-OVZ-31TN_FnOlKXIHEwH0Q==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.illposed.osc.argument.handler.AwtColorArgumentHandler.getJavaClass(AwtColorArgumentHandler.java:39) 
        at com.illposed.osc.OSCSerializer.<init>(OSCSerializer.java:97) 
        at com.illposed.osc.OSCSerializerAndParserBuilder.buildSerializer(OSCSerializerAndParserBuilder.java:60) 
        at com.illposed.osc.transport.channel.OSCDatagramChannel.send(OSCDatagramChannel.java:96) 
        at com.illposed.osc.transport.udp.UDPTransport.send(UDPTransport.java:134) 
        at com.illposed.osc.transport.OSCPortOut.send(OSCPortOut.java:119) 
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.send(EosConsoleComm.kt:47) 
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.send$default(EosConsoleComm.kt:45) 
        at org.dankeenan.wearrfr.console.EosConsoleComm$Companion.discover(EosConsoleComm.kt:40) 
        at org.dankeenan.wearrfr.consolelist.ConsoleListViewModel$discover$1.invokeSuspend(ConsoleListViewModel.kt:49) 
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6680) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
ManuDev9 commented 2 years ago

Hello my friends, this is a Java workaround from the application perspective. No need to pick weird snapshots:

            OSCSerializerAndParserBuilder serializer = new OSCSerializerAndParserBuilder();
            serializer.setUsingDefaultHandlers(false);
            List<ArgumentHandler> defaultParserTypes = Activator.createSerializerTypes();
            defaultParserTypes.remove(16);
            char typeChar = 'a';
            for (ArgumentHandler argumentHandler:defaultParserTypes) {
                serializer.registerArgumentHandler(argumentHandler, typeChar);
                typeChar++;
            }
            mOscPortOut = new OSCPortOut(serializer,
                    new InetSocketAddress(AppData.getOscRemoteAddress(), AppData.getOscPortOutNumber()));

Enjoy

hoijui commented 2 years ago

Possible fix committed, please test. Sorry, I can not test on android. My hopes that it will work now are not too high, but... let's see. If this does not work, I don't know if it is possible to go full-in reflection style on AwtColorArgumentHandler, regarding java.awt.Color.

hoijui commented 2 years ago

I went ahead and moved (hopefully) all AWT related code into a different artifact: com.illposed.osc:java-se-addons

As long as you don't list this as a dependency, you should be fine in Android now.

Please someone test on android, so I can make a release.

JellevanAbbema commented 2 years ago

I'm having a look at it right now. I'm using the 0.9-SNAPSHOT from sonatype but I'm not sure if that's the latest version. I'm unable to compile from the git source (a lot of problems running build). If the jar from sonatype is up to date then the fix did not work, I'm still having the same issue. From what I can tell the java-se-addons is not used as a dependency.

hoijui commented 2 years ago

I'm unable to compile from the git source (a lot of problems running build).

Ohh.. cant you give info on that? which java version, what kind of problems, how do you build?

I did not release the snapshot before, sorry. I should have. it is stil a manual process. Now it should be up to date.

JellevanAbbema commented 2 years ago

I did not release the snapshot before, sorry. I should have. it is stil a manual process. Now it should be up to date. Yeah that's what I expected but not a problem at all, happens to the best of us.

But, at first sight, there don't seem to be any problems! Didn't really do a deep dive into it but I don't think there should be any problems with this fix, thank you very much! I really appreciate your work.

About my building issues: I just downloaded the repository in Intellij. I usually work with maven so I tried to just 'mvn clean install' the core artifact. I believe in the end it got stuck running the tests (Tests run: 267, Failures: 1, Errors: 22, Skipped: 0) but I also get allot of errors/warnings when I open the pom files (mainly the parent file). Didn't look further into it since I don't have the time to do so and I don't really need to build my own version.

hoijui commented 2 years ago

Ahh nice, thanks @JellevanAbbema !

DodoSeal commented 9 months ago

I don't know where any of the new fixes mentioned here are. I am on version 0.8 and a getting the same error with android currently.

hoijui commented 5 months ago

@DodoSeal they are in the 0.9-SNAPSHOT release. you can refer to it after putting this in your maven file:

    <repositories>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
    </repositories>