JetBrains / skiko

Kotlin Multiplatform bindings to Skia
Apache License 2.0
1.83k stars 118 forks source link

skiko-android supposedly includes skiko-awt in itself #930

Closed altered-dev closed 1 month ago

altered-dev commented 5 months ago

Hello! I am working on a multiplatform project that is using Skiko for rendering. I set up an Android app, but when I ran it, it just ...didn't work.

For the purpose of research I created a minimal Android project with just Skiko as a dependency, so there is no doubt in me having set up the project in a wrong way.

At first, the issue was having duplicate classes (the presence of skiko-awt is suspicious, it's not included in the project):

Duplicate class org.jetbrains.skia.Actuals_jvmKt found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)
Duplicate class org.jetbrains.skia.AnimationDisposalMethod found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)
Duplicate class org.jetbrains.skia.AnimationDisposalMode found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)
Duplicate class org.jetbrains.skia.AnimationFrameInfo found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)
Duplicate class org.jetbrains.skia.AnimationFrameInfo$Companion found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)
Duplicate class org.jetbrains.skia.ArrayDecoder found in modules skiko-android-0.8.4 (org.jetbrains.skiko:skiko-android:0.8.4) and skiko-awt-0.8.4 (org.jetbrains.skiko:skiko-awt:0.8.4)

...and lots and lots of similar lines

But when I switched the dependency from implementation to compileOnly, I got the following message as the crash report (there's no AWT in Android):

20:24:01.042  E  FATAL EXCEPTION: main
                 Process: com.example.skikotest, PID: 16541
                 java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/swing/JPanel;
                    at java.lang.Class.newInstance(Native Method)
                    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
                    at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
                    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
                    at android.os.Handler.dispatchMessage(Handler.java:106)
                    at android.os.Looper.loop(Looper.java:223)
                    at android.app.ActivityThread.main(ActivityThread.java:7656)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                 Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.swing.JPanel" on path: DexPathList[[zip file "/data/app/~~caQMnoNCFAJu1AFzaBZqTA==/com.example.skikotest-zMBetfoKn8czjtpWqdzJqg==/base.apk"],nativeLibraryDirectories=[/data/app/~~caQMnoNCFAJu1AFzaBZqTA==/com.example.skikotest-zMBetfoKn8czjtpWqdzJqg==/lib/x86, /system/lib, /system_ext/lib]]
                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                    at java.lang.Class.newInstance(Native Method) 
                    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) 
                    at android.app.Instrumentation.newActivity(Instrumentation.java:1253) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
                    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
                    at android.os.Handler.dispatchMessage(Handler.java:106) 
                    at android.os.Looper.loop(Looper.java:223) 
                    at android.app.ActivityThread.main(ActivityThread.java:7656) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

I also tried downgrading the version down to 0.8.0, which did not help. Is there any solution to this?

sbilsky commented 3 months ago
android {
    configurations.all {
        exclude(group = "org.jetbrains.skiko", module = "skiko-awt")
    }
}

This workaround works for me.

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.