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

Summary: Android 4.1: java.lang.NoClassDefFoundError: android.bluetooth.BluetoothManager
Product: SDL Reporter: Jordan Christiansen <xordspar0>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Android (All)   
Attachments: Patch to disable BluetoothManager for old versions of Android

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