AndroidBluetoothLibrary icon indicating copy to clipboard operation
AndroidBluetoothLibrary copied to clipboard

Crash when set minifyEnabled true with error ArrayIndexOutOfBoundsException

Open Tho391 opened this issue 4 years ago • 1 comments

I am try to set minifyEnabled true in build.gradle and it crash when I call init

        val config = BluetoothConfiguration().apply {
            context = applicationContext
            bluetoothServiceClass = BluetoothClassicService::class.java
            bufferSize = 1024
            characterDelimiter = '\n'
            deviceName = "Android"
            callListenersInMainThread = true
            uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb")
        }

BluetoothService.init(config)

This is log for crash:

2021-09-12 10:30:19.942 4103-4103/ E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.dev, PID: 4103 java.lang.RuntimeException: Unable to create application com.android.MainApplication: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6733) at android.app.ActivityThread.access$1500(ActivityThread.java:247) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2057) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at com.github.douglasjunior.bluetoothclassiclibrary.BluetoothService.e(SourceFile:188) at com.android.MainApplication.t(SourceFile:131) at com.android.MainApplication.onCreate(SourceFile:127) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6728) at android.app.ActivityThread.access$1500(ActivityThread.java:247)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2057)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:201)  at android.os.Looper.loop(Looper.java:288)  at android.app.ActivityThread.main(ActivityThread.java:7842)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

So I go to source com.github.douglasjunior.bluetoothclassiclibrary.BluetoothService.e(SourceFile:188) and found that this line make app crash mDefaultConfiguration.bluetoothServiceClass.getDeclaredConstructors()[0]

public static void init(BluetoothConfiguration config) {
        mDefaultConfiguration = config;
        if (mDefaultServiceInstance != null) {
            mDefaultServiceInstance.stopService();
            mDefaultServiceInstance = null;
        }
        try {
            Constructor<? extends BluetoothService> constructor =
                    (Constructor<? extends BluetoothService>) mDefaultConfiguration.bluetoothServiceClass.getDeclaredConstructors()[0];
            constructor.setAccessible(true);
            BluetoothService bluetoothService = constructor.newInstance(mDefaultConfiguration);
            mDefaultServiceInstance = bluetoothService;
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

Tho391 avatar Sep 12 '21 03:09 Tho391

You probably need to add the "com.github.douglasjunior" package to your proguard exceptions.

douglasjunior avatar Sep 12 '21 23:09 douglasjunior