We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5450 - Android 4.1: java.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager
Summary: Android 4.1: java.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Android (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-08 01:40 UTC by Jordan Christiansen
Modified: 2021-01-08 02:23 UTC (History)
0 users

See Also:


Attachments
Patch to disable BluetoothManager for old versions of Android (1.51 KB, patch)
2021-01-08 01:40 UTC, Jordan Christiansen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jordan Christiansen 2021-01-08 01:40:29 UTC
Created attachment 4642 [details]
Patch to disable BluetoothManager for old versions of Android

On Android, prior to API version 18 (i.e. Android 4.1 and older) the BluetoothManager API did not exist yet. However, SDL always uses BluetoothManager when Bluetooth is enabled, causing a crash at runtime with the following stack trace:

E/AndroidRuntime: FATAL EXCEPTION: SDLActivity
    java.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager
        at org.libsdl.app.HIDDeviceManager.initializeBluetooth(HIDDeviceManager.java:377)
        at org.libsdl.app.HIDDeviceManager.<init>(HIDDeviceManager.java:153)
        at org.libsdl.app.HIDDeviceManager.acquire(HIDDeviceManager.java:36)
        at org.libsdl.app.SDLActivity.startNative(SDLActivity.java:260)
        at org.libsdl.app.SDLActivity.onCreate(SDLActivity.java:240)
        at org.love2d.android.GameActivity.onCreate(GameActivity.java:117)
        at android.app.Activity.performCreate(Activity.java:5063)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

SDL should not try to use the BluetoothManager API if the OS is at an API version less than 18.

I attached a patch that simply disables Bluetooth if BluetoothManager is not present. Ideally Bluetooth should still be supported, but I'm not sure if there are any non-BLE devices that we would need to support in a game.

This bug continues from a discussion in Discourse: https://discourse.libsdl.org/t/java-lang-noclassdeffounderror-android-bluetooth-bluetoothmanager/27722
Comment 1 Sam Lantinga 2021-01-08 02:23:02 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/a8e6474302ea