livekit / client-sdk-android

LiveKit SDK for Android
https://docs.livekit.io
Apache License 2.0
160 stars 63 forks source link

SDK will crash on Android 8 or 9 #370

Open wzJun1 opened 5 months ago

wzJun1 commented 5 months ago

Describe the bug

When initializing the video room.initVideoRenderer, crash logs:

01-31 11:02:24.158 10259 10259 I zygote64: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/FloatBuffer; in class Ljava/nio/FloatBuffer; or its super classes (declaration of 'java.nio.FloatBuffer' appears in /system/framework/core-oj.jar) 01-31 11:02:24.158 10259 10259 I zygote64: (Throwable with no stack trace) 01-31 11:02:24.158 10259 10259 I zygote64: 01-31 11:02:24.158 10259 10259 W System.err: java.lang.NoClassDefFoundError: org.webrtc.GlRectDrawer 01-31 11:02:24.159 10259 10259 W System.err: at io.livekit.android.renderer.TextureViewRenderer.init$default(TextureViewRenderer.kt:85) 01-31 11:02:24.159 10259 10259 W System.err: at io.livekit.android.room.Room.initVideoRenderer(Room.kt:1019) 01-31 11:02:24.159 10259 10259 W System.err: at com.wzjun.activity.MeetActivity.initCallKit(MeetActivity.kt:1261) 01-31 11:02:24.159 10259 10259 W System.err: at com.wzjun.activity.MeetActivity.checkPermissionAndConnectRoom(MeetActivity.kt:1174) 01-31 11:02:24.160 10259 10259 W System.err: at com.wzjun.activity.MeetActivity.onCreate(MeetActivity.kt:169) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.Activity.performCreate(Activity.java:7066) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.Activity.performCreate(Activity.java:7057) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1216) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3061) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.ActivityThread.-wrap12(Unknown Source:0) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1747) 01-31 11:02:24.160 10259 10259 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106) 01-31 11:02:24.160 10259 10259 W System.err: at android.os.Looper.loop(Looper.java:192) 01-31 11:02:24.160 10259 10259 W System.err: at android.app.ActivityThread.main(ActivityThread.java:6825) 01-31 11:02:24.160 10259 10259 W System.err: at java.lang.reflect.Method.invoke(Native Method) 01-31 11:02:24.160 10259 10259 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 01-31 11:02:24.160 10259 10259 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886) 01-31 11:02:24.160 10259 10259 W System.err: Caused by: java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/FloatBuffer; in class Ljava/nio/FloatBuffer; or its super classes (declaration of 'java.nio.FloatBuffer' appears in /system/framework/core-oj.jar) 01-31 11:02:24.160 10259 10259 W System.err: at org.webrtc.GlUtil.createFloatBuffer(GlUtil.java:47) 01-31 11:02:24.160 10259 10259 W System.err: at org.webrtc.GlGenericDrawer.(GlGenericDrawer.java:75) 01-31 11:02:24.161 10259 10259 W System.err: ... 18 more

Device Info:

wzJun1 commented 5 months ago

If I switch the version of webrtc-sdk it will work fine

I switched 114.5735.05 to 104.5112.10

implementation 'io.github.webrtc-sdk:android:104.5112.10'

@davidliu

wzJun1 commented 5 months ago

I guess it is because webrtc-sdk is packaged using java11. Can this problem be solved?

davidliu commented 5 months ago

I'm unable to repro this crash on my Android 9.0 device with the sample apps in the repo. Try adding the following to your app/build.gradle file in the android section:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
wzJun1 commented 5 months ago

I'm unable to repro this crash on my Android 9.0 device with the sample apps in the repo. Try adding the following to your app/build.gradle file in the android section:

compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
}

It is invalid because I always have JavaVersion.VERSION_1_8 in compileOptions of app/build.gradle

Although Android 8 has a small market share, the main target group of our project is middle-aged and elderly people, and most of their devices have low configurations, so there are relatively more mobile phones equipped with Android 8. It is certain that this type of problem will occur on the Android 8 platform of vivo or MEIZU, but there is no such problem with Livekit SDK version 1.2.0. As I said above, when I run Livekit When SDK (1.6.0) is packaged locally and uses io.github.webrtc-sdk:android:104.5112.10, it will not have this problem.

I learned through google search that it is most likely caused by Java11. The following are the search results. I hope it can help you find and solve the problem. Thank you very much!

It is an issue from other projects and has nothing to do with livekit, but it is very similar to the problems we currently encounter when using livekit. I hope it can help: https://github.com/react-native-webrtc/react-native-webrtc/issues/1310

davidliu commented 5 months ago

Does setting the targetCompatibility to targetCompatibility JavaVersion.VERSION_11 work for you?

wzJun1 commented 5 months ago

Sorry, due to project policy, I cannot modify targetCompatibility, and our project has been fixed to JavaVersion.VERSION_1_8 over the years.

Does setting the targetCompatibility to targetCompatibility JavaVersion.VERSION_11 work for you?

wzJun1 commented 5 months ago

Currently I use io.github.webrtc-sdk:android:104.5112.10 and livekit 1.6.0. Everything is fine for the time being, not particularly urgent. But I still hope to use the latest version

davidliu commented 5 months ago

Can you see if the sample apps crash in the same way as well?

wzJun1 commented 5 months ago

OK, Wait a minute, I'm going to test

wzJun1 commented 5 months ago

There is no problem with the demo, which is really strange. We just upgraded a version of livekit sdk, and this happened.

I'll check the code again.

wzJun1 commented 5 months ago

But as soon as I switch to version 1.2.0, Android 8 will work fine. It's amazing

davidliu commented 5 months ago

Can you upload a sample project reproing the issue? It's likely a difference in build.gradle settings.

wzJun1 commented 5 months ago

I found that this problem occurs when using livekit sdk 1.6.0 on Android 8 or 9 when the gradle version is lower.

for example:

Android gradle plugin version = 4.2.2
Gradle version = 6.7.1

There will be problems using livekit sdk 1.6.0 at this time.

But there is no problem using livekit sdk 1.2.0 at this time.

Due to problems with our project, it may not be possible to modify the Gradle version, so is there a better solution?