问题描述
在真机运行 flutter_gallery 时,出现了一个缺少android.permission.UPDATE_DEVICE_STATS
权限的错误。
HM 1S • 1f5da867 • android-arm • Android 4.4.4 (API 19)
错误详情
E/flutter (27757): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)] java.lang.SecurityException: uid 10104 does not have android.permission.UPDATE_DEVICE_STATS.
E/flutter (27757): at android.os.Parcel.readException(Parcel.java:1489)
E/flutter (27757): at android.os.Parcel.readException(Parcel.java:1443)
E/flutter (27757): at android.app.ActivityManagerProxy.reportActivityFullyDrawn(ActivityManagerNative.java:4646)
E/flutter (27757): at android.app.Activity.reportFullyDrawn(Activity.java:1486)
E/flutter (27757): at io.flutter.demo.gallery.MainActivity$1.onFirstFrame(MainActivity.java:33)
E/flutter (27757): at io.flutter.view.FlutterView.onFirstFrame(FlutterView.java:839)
E/flutter (27757): at io.flutter.view.FlutterNativeView.onFirstFrame(FlutterNativeView.java:224)
E/flutter (27757): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (27757): at android.os.MessageQueue.next(MessageQueue.java:138)
E/flutter (27757): at android.os.Looper.loop(Looper.java:123)
E/flutter (27757): at android.app.ActivityThread.main(ActivityThread.java:5052)
E/flutter (27757): at java.lang.reflect.Method.invokeNative(Native Method)
E/flutter (27757): at java.lang.reflect.Method.invoke(Method.java:515)
E/flutter (27757): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
E/flutter (27757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
E/flutter (27757): at dalvik.system.NativeStart.main(Native Method)
E/flutter (27757):
F/flutter (27757): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(112)] Check failed: CheckException(env).
F/libc (27757): Fatal signal 6 (SIGABRT) at 0x00006c6d (code=-6), thread 27757 (er.demo.gallery)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/armani/armani:4.4.4/KTU84P/6.10.1:user/release-keys'
Revision: '0'
pid: 27757, tid: 27757, name: er.demo.gallery >>> io.flutter.demo.gallery <<<
解决方案
添加声明 android:sharedUserId="android.uid.system"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.demo.gallery"
android:sharedUserId="android.uid.system">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="Gallery" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Light.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>