Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlutterBluetoothSerialPlugin.java uses or overrides a deprecated API. #212

Open
HamzaKlf opened this issue Jan 29, 2024 · 4 comments
Open

Comments

@HamzaKlf
Copy link

Lately, my generated Flutter APK has been experiencing issues with controlling the Android Bluetooth, leading to difficulties in establishing connections.

Flutter 3.13.0 • channel stable • https://github.com/flutter/flutter.git
Tools • Dart 3.1.0 • DevTools 2.25.0

while generating the Apk, the following error is shown:

Note: C:\Users\Usuario\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_bluetooth_serial-0.4.0\android\src\main\java\io\github\edufolly\flutterbluetoothserial\FlutterBluetoothSerialPlugin.java uses or overrides a deprecated API.

During the debugging process, the following message appears when attempting to disable the Android Bluetooth from within the app:

I/BluetoothAdapter( 2445): disable()
I/BluetoothAdapter( 2445): BluetoothAdapter() : com.example.test_reactive
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): Failed to handle method call
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10384, packageName = com.example.test_reactive, attributionTag = null, token = android.os.BinderProxy@ff247a7, next = null }: disable
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Parcel.createExceptionOrNull(Parcel.java:2437)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Parcel.createException(Parcel.java:2421)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Parcel.readException(Parcel.java:2404)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Parcel.readException(Parcel.java:2346)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.bluetooth.IBluetoothManager$Stub$Proxy.disable(IBluetoothManager.java:1046)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.bluetooth.BluetoothAdapter.disable(BluetoothAdapter.java:2271)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at io.github.edufolly.flutterbluetoothserial.FlutterBluetoothSerialPlugin$FlutterBluetoothSerialMethodCallHandler.onMethodCall(FlutterBluetoothSerialPlugin.java:593)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): Caused by: android.os.RemoteException: Remote stack trace:
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.server.BluetoothManagerService.checkPermissionForDataDelivery(BluetoothManagerService.java:5032)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.server.BluetoothManagerService.checkConnectPermissionForDataDelivery(BluetoothManagerService.java:5050)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.server.BluetoothManagerService.checkBluetoothPermissions(BluetoothManagerService.java:1504)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at com.android.server.BluetoothManagerService.disable(BluetoothManagerService.java:1931)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445): at android.bluetooth.IBluetoothManager$Stub.onTransact(IBluetoothManager.java:473)
E/MethodChannel#flutter_bluetooth_serial/methods( 2445):
E/flutter ( 2445): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10384, packageName = com.example.test_reactive, attributionTag = null, token = android.os.BinderProxy@ff247a7, next = null }: disable, null, java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource { uid = 10384, packageName = com.example.test_reactive, attributionTag = null, token = android.os.BinderProxy@ff247a7, next = null }: disable
E/flutter ( 2445): at android.os.Parcel.createExceptionOrNull(Parcel.java:2437)
E/flutter ( 2445): at android.os.Parcel.createException(Parcel.java:2421)
E/flutter ( 2445): at android.os.Parcel.readException(Parcel.java:2404)
E/flutter ( 2445): at android.os.Parcel.readException(Parcel.java:2346)
E/flutter ( 2445): at android.bluetooth.IBluetoothManager$Stub$Proxy.disable(IBluetoothManager.java:1046)
E/flutter ( 2445): at android.bluetooth.BluetoothAdapter.disable(BluetoothAdapter.java:2271)
E/flutter ( 2445): at io.github.edufolly.flutterbluetoothserial.FlutterBluetoothSerialPlugin$FlutterBluetoothSerialMethodCallHandler.onMethodCall(FlutterBluetoothSerialPlugin.java:593)
E/flutter ( 2445): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter ( 2445): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 2445): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter ( 2445): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 2445): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 2445): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 2445): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter ( 2445): at android.os.Looper.loop(Looper.java:313)
E/flutter ( 2445): at android.app.ActivityThread.main(ActivityThread.java:8663)
E/flutter ( 2445): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 2445): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/flutter ( 2445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter ( 2445): Caused by: android.os.RemoteException: Remote stack trace:
E/flutter ( 2445): at com.android.server.BluetoothManagerService.checkPermissionForDataDelivery(BluetoothManagerService.java:5032)
E/flutter ( 2445): at com.android.server.BluetoothManagerService.checkConnectPermissionForDataDelivery(BluetoothManagerService.java:5050)
E/flutter ( 2445): at com.android.server.BluetoothManagerService.checkBluetoothPermissions(BluetoothManagerService.java:1504)
E/flutter ( 2445): at com.android.server.BluetoothManagerService.disable(BluetoothManagerService.java:1931)
E/flutter ( 2445): at android.bluetooth.IBluetoothManager$Stub.onTransact(IBluetoothManager.java:473)
E/flutter ( 2445):
E/flutter ( 2445): )
E/flutter ( 2445): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
E/flutter ( 2445): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
E/flutter ( 2445):
E/flutter ( 2445): #2 FlutterBluetoothSerial.requestDisable (package:flutter_bluetooth_serial/FlutterBluetoothSerial.dart:87:7)
E/flutter ( 2445):
E/flutter ( 2445): #3 _MainPage.build..future (package:flutter_application_1/MainPage.dart:109:21)
E/flutter ( 2445):
E/flutter ( 2445):

pubspec.yaml:

name: flutter_application_1
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.1.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  permission_handler: ^11.0.1
  cupertino_icons: ^1.0.2
  flutter_bluetooth_serial: ^0.4.0
  scoped_model: ^2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>


    <application
        android:label="test_reactive"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

build.gradle:

ext.kotlin_version = '1.7.10'
classpath 'com.android.tools.build:gradle:7.3.0'
@haisamk18
Copy link

Have you got any solution for this? I am facing this issue while releasing the .apk file

@HamzaKlf
Copy link
Author

HamzaKlf commented Feb 2, 2024

So far, there have been no updates for the flutter_bluetooth_serial library in the past two years, causing it to become obsolete. Consequently, I've transitioned to using the flutter_reactive_ble library, which is functioning well without any issues related to Bluetooth connection or permissions.

@haisamk18
Copy link

haisamk18 commented Feb 3, 2024 via email

@HamzaKlf
Copy link
Author

HamzaKlf commented Feb 5, 2024

Following Dart and Flutter packages can help you add Bluetooth, NFC, Beacon, BLE and other communication feature to your app:
https://fluttergems.dev/bluetooth-nfc-beacon/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants