三星 phone 中的 Flutter 构建失败,权限拒绝:来自 android 的广播以用户 -1 身份向 运行 请求,但正在从用户 0 调用

Flutter build fails in Samsung phone , Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0

尝试在 Samsung Note 8 phone 上构建一个以前可以运行的应用程序,这是错误 Permission Denial: broadcast from android asks to 运行 as user -1 但正在从用户 0

呼叫

现在我明白了 INTERACT_ACROSS_USERS_FULL 只有访问系统功能的系统应用程序才需要权限。我的这个app之前是可以正常使用的,升级了flutter和dart版本,也升级了MobileOS.

即使在所有清单文件中添加了这些权限,仍然无法正常工作,

<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>

也试过这个 SO,甚至通过调整 phone 上的开发人员选项工作了一次,因为我在这里给出了答案 tweaking developer options 但现在也不起作用了。

这是我的flutter医生出来的,

[✓] Flutter (Channel master, 2.6.0-1.0.pre.153, on macOS 11.5.1 20G80 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (2 available)

完整的错误是这样的,

D/vndksupport( 5675): Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
E/flutter ( 5675): [ERROR:flutter/fml/platform/android/jni_util.cc(182)] java.lang.SecurityException: Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
E/flutter ( 5675):  at android.os.Parcel.createException(Parcel.java:1966)
E/flutter ( 5675):  at android.os.Parcel.readException(Parcel.java:1934)
E/flutter ( 5675):  at android.os.Parcel.readException(Parcel.java:1884)
E/flutter ( 5675):  at android.app.IActivityManager$Stub$Proxy.reportActivityFullyDrawn(IActivityManager.java:7312)
E/flutter ( 5675):  at android.app.Activity.reportFullyDrawn(Activity.java:2092)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterActivity.onFlutterUiDisplayed(FlutterActivity.java:1100)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onFlutterUiDisplayed(FlutterActivityAndFragmentDelegate.java:88)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterView.onFlutterUiDisplayed(FlutterView.java:133)
E/flutter ( 5675):  at io.flutter.embedding.engine.FlutterJNI.onFirstFrame(FlutterJNI.java:462)
E/flutter ( 5675):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 5675):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 5675):  at android.os.Looper.loop(Looper.java:181)
E/flutter ( 5675):  at android.app.ActivityThread.main(ActivityThread.java:7073)
E/flutter ( 5675):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 5675):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/flutter ( 5675):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter ( 5675): Caused by: android.os.RemoteException: Remote stack trace:
E/flutter ( 5675):  at com.android.server.am.UserController.handleIncomingUser(UserController.java:1818)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:25789)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:25720)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:26590)
E/flutter ( 5675):  at android.app.ContextImpl.sendBroadcastAsUser(ContextImpl.java:1264)
E/flutter ( 5675): 
E/flutter ( 5675): 
F/flutter ( 5675): [FATAL:flutter/shell/platform/android/platform_view_android_jni_impl.cc(1220)] Check failed: fml::jni::CheckException(env). 
F/libc    ( 5675): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 5675 (bro.neighbroapp), pid 5675 (bro.neighbroapp)

这是最新 Flutter 版本的问题,我用下面的 eidt 修复了它,

这是一种解决方法,对我有用。

  1. 转到MainActivity.kt
  2. 导入 import android.os.Build
  3. 粘贴这个
    override fun onFlutterUiDisplayed() {
        if (Build.VERSION.SDK_INT >= 100) { //I gave 100 just to confirm , it shoud be android ver 10
            reportFullyDrawn();
        }
    }
  1. flutter clean
  2. flutter run