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

App crashes on devices with Android 12 #80

Closed
DmytroMeleshko opened this issue Jan 24, 2022 · 12 comments · Fixed by #93
Closed

App crashes on devices with Android 12 #80

DmytroMeleshko opened this issue Jan 24, 2022 · 12 comments · Fixed by #93
Labels
bug Something isn't working

Comments

@DmytroMeleshko
Copy link

Describe the issue

Application crashes on startup on Android 12 real devices, while on emulators with the same Android version it works great.

Error log details:

✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
E/AndroidRuntime(24078): FATAL EXCEPTION: main
E/AndroidRuntime(24078): Process: org.scopeevents.Celebrate, PID: 24078
E/AndroidRuntime(24078): java.lang.RuntimeException: Unable to create application org.scopeevents.Celebrate.MainApplication: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@cf128ae8: GattService getDevicesMatchingConnectionStates
E/AndroidRuntime(24078): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6730)
E/AndroidRuntime(24078): 	at android.app.ActivityThread.access$1500(ActivityThread.java:247)
E/AndroidRuntime(24078): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
E/AndroidRuntime(24078): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(24078): 	at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(24078): 	at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(24078): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime(24078): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(24078): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(24078): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(24078): Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@cf128ae8: GattService getDevicesMatchingConnectionStates
E/AndroidRuntime(24078): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
E/AndroidRuntime(24078): 	at android.os.Parcel.createException(Parcel.java:2409)
E/AndroidRuntime(24078): 	at android.os.Parcel.readException(Parcel.java:2392)
E/AndroidRuntime(24078): 	at android.os.Parcel.readException(Parcel.java:2334)
E/AndroidRuntime(24078): 	at android.bluetooth.IBluetoothGatt$Stub$Proxy.getDevicesMatchingConnectionStates(IBluetoothGatt.java:1690)
E/AndroidRuntime(24078): 	at android.bluetooth.BluetoothManager.getDevicesMatchingConnectionStates(BluetoothManager.java:200)
E/AndroidRuntime(24078): 	at android.bluetooth.BluetoothManager.getConnectedDevices(BluetoothManager.java:160)
E/AndroidRuntime(24078): 	at com.squareup.logging.RealBluetoothDevicesCountInitializer.setupInitialConnectedDevices(RealBluetoothDevicesCountInitializer.kt:54)
E/AndroidRuntime(24078): 	at com.squareup.logging.BluetoothAclConnectionReceiver.onEnterScope(BluetoothAclConnectionReceiver.kt:27)
E/AndroidRuntime(24078): 	at shadow.mortar.MortarScope.register(MortarScope.java:199)
E/AndroidRuntime(24078): 	at com.squareup.RegisterAppDelegate.onEnterScope(RegisterAppDelegate.java:444)
E/AndroidRuntime(24078): 	at shadow.mortar.MortarScope.register(MortarScope.java:199)
E/AndroidRuntime(24078): 	at com.squareup.RegisterAppDelegate.createAppScope(RegisterAppDelegate.java:335)
E/AndroidRuntime(24078): 	at com.squareup.RegisterAppDelegate.onCreate(RegisterAppDelegate.java:189)
E/AndroidRuntime(24078): 	at com.squareup.sdk.reader.internal.AppBootstrapHolder.onCreate(AppBootstrapHolder.java:23)
E/AndroidRuntime(24078): 	at com.squareup.sdk.reader.ReaderSdk.initialize(ReaderSdk.java:38)
E/AndroidRuntime(24078): 	at org.scopeevents.Celebrate.MainApplication.onCreate(MainApplication.java:22)
E/AndroidRuntime(24078): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211)
E/AndroidRuntime(24078): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6725)
E/AndroidRuntime(24078): 	... 9 more

Expected behavior

The application should build successfully

Environment:

  • platform: Android
  • OS and version: Android 12
  • dev environment: MacOS
  • Reader SDK version: 1.5.1

[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale ru-UA)
• Flutter version 2.8.1 at ...
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 77d935af4d (6 weeks ago), 2021-12-16 08:37:33 -0800
• Engine revision 890a5fca2e
• Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at ...
• Platform android-32, build-tools 32.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.63.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
• Pixel 4a (mobile) • 15051JEC215525 • android-arm64 • Android 12 (API 31)
• No issues found!

@DmytroMeleshko DmytroMeleshko added the bug Something isn't working label Jan 24, 2022
@john-tmc
Copy link

john-tmc commented May 3, 2022

Hope this can resolve any similar issues that others might have.
I found that the java library com.squareup.sdk.reader.ReaderSdk crashes before permission is actually requested.

New bluetooth permission for Android 12+

Long term solution :
Square Dev needs to update the native Reader SDK for the newest bluetooth permission: BLUETOOTH_SCAN and BLUETOOTH_CONNECT

Short term solution (your setup may differ, but the logic would be the same):

AndroidManifest.xml

...
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
...

MainApplication.kt

...
public class MainApplication: FlutterApplication() {
    override fun onCreate() {
        super.onCreate()
        FlutterMain.startInitialization(this);
    } 
}
...

MainActivity.kt

...
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import com.blackairplane.vendor.MainApplication;
import com.squareup.sdk.reader.ReaderSdk;   
import android.app.Application

class MainActivity: FlutterActivity() {
    private val CHANNEL = "com.demo.vendor/square"
    var readerInitialized: Boolean = false;

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
        call, result ->
            if (call.method == "VERSION") result.success(android.os.Build.VERSION.RELEASE)
            else if (!readerInitialized && call.method == "INITIALIZE" ) {
                readerInitialized = true;
                ReaderSdk.initialize(applicationContext as Application);
                result.success("READER SDK Initialized");
            }
        }
    }
}
...

main.dart

...
...
const platform = MethodChannel('com.demo.vendor/square');
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
...

  var activateReader = true;
  if (Platform.isAndroid && int.parse((await platform.invokeMethod('VERSION'))) >= 12) {
      activateReader = await Permission.bluetoothConnect.request().isGranted &&
          await Permission.bluetoothScan.request().isGranted;
  } else {
      activateReader = await Permission.bluetooth.request().isGranted;
  }
   if (activateReader) log.i(await platform.invokeMethod('INITIALIZE'));
  }
...
}
...
...

@CharmisG
Copy link
Contributor

CharmisG commented May 6, 2022

Please pull latest update it's fixes.

@CharmisG CharmisG closed this as completed May 6, 2022
@CurtHubb
Copy link

This issue is still occurring for me with the latest fixes

@TatsuUkraine
Copy link
Contributor

@CharmisG I can confirm that described issue is still there. Workaround from @john-tmc works, but it's still a workaround

@CharmisG
Copy link
Contributor

CharmisG commented Aug 4, 2022

@TatsuUkraine @CurtHubb @john-tmc
Sorry for the trouble but I'm also figuring out an issue from my side now I have kept all required permission for android 12 on flutter 3 so can you please check the latest code and let me know the status?

@TatsuUkraine
Copy link
Contributor

@CharmisG if to follow getting started docs with the most recent changes it doesn't solve anything, app still crashes during the start

@CharmisG
Copy link
Contributor

@TatsuUkraine @CurtHubb @john-tmc
Sorry for the delay but I'm figuring out the issue and update you soon.

@CharmisG CharmisG reopened this Aug 16, 2022
@CharmisG
Copy link
Contributor

@TatsuUkraine @CurtHubb @john-tmc
Sorry for the delay but we are using the permission_handler plugin and this plugin itself has this permission error that's why it's crashing so we are waiting for this(permission_handler) plugin update and we are continuously touched with this plugin and I'll let you know when we get any response and will update you!

Plugin link: https://pub.dev/packages/permission_handler

Thank you !!

@TatsuUkraine
Copy link
Contributor

@CharmisG I'm not sure that the issue is in permission handles plugin, reader sdk plugin doesn't uses it

@TatsuUkraine
Copy link
Contributor

Do you have a link to an issue that you mentioned?

@CharmisG
Copy link
Contributor

Yes Sure
Please check below link :
Baseflow/flutter-permission-handler#884

@TatsuUkraine
Copy link
Contributor

@CharmisG I still not sure if it has anything to do with permission handler. Please read release notes of android reader sdk https://developer.squareup.com/docs/changelog/mobile-logs/2022-03-30 and then read about these 2 permissions. They are dangerous, which means that they should be requested in runtime. And the ReaderSdk.initialize requires to have these permissions granted before you invoked it.

Here you have a working example #80 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants