I have an Android application and need to implement bluetooth low energy functionality. The BLE features should run on devices with Android API Level > 26 (Android 8), but the app should also start on devices with Android > 17 (Android 4.2). I have tested this app on Android 8 and 4.4 and there are no problems. If i let the app run on devices with Android 4.2.2 it crashes just after the start. Logs look like that:
AndroidRuntime: FATAL EXCEPTION: main java.lang.NoClassDefFoundError: android/bluetooth/BluetoothGatt
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.bluetooth.BluetoothGatt” on path: /data/app/com.android.codeDevice-1.apk
Android project configuration:
compileSdkVersion = 26 buildToolsVersion = '27.0.3' minSdkVersion = 17 targetSdkVersion = 26
Also MultiDex is enabled and my main application extends MultiDexApplication.
Is there a need to config the proguard rules? I don’t know how to fix that, thank you for any help.
Advertisement
Answer
As can be seen in the documentation, BluethoothGatt was added in API level 18: https://developer.android.com/reference/android/bluetooth/BluetoothGatt .
Your current minSDK is 17. You either have to update your minSDK or find another solution (e.g. 3rd party lib, etc.)