flutter 缺少权限android.permission.蓝牙在抖动时运行在Android 12上

64jmpszr  于 2022-12-19  发布在  Flutter
关注(0)|答案(1)|浏览(152)

我遇到以下错误...
E/B热打印机插件(9243):UID 10581 / PID 9243缺少权限android。权限。蓝牙
E/B热打印机插件(9243):java.lang.SecurityException:UID 10581 / PID 9243缺少权限android.权限。蓝牙
E/B热打印机插件(9243):在android.os.宗地中创建异常或空(宗地. java:2426)
这是我的Android清单. xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.soerjdev.enakabe">
   <application
        android:label="Enakabe"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            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"
            android:exported="true">
            <!-- 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"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <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>

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

这是我的身材

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.soerjdev.enakabe"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:2.0.1'
}

这是pubspeck yaml中的依赖项:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_typeahead: ^4.1.1
  shared_preferences: ^2.0.1
  go_router: ^5.1.5
  double_back_to_close_app: ^2.1.0
  provider: ^6.0.4
  image_picker: ^0.7.1
  http: ^0.13.5
  path_provider: ^2.0.11
  path: ^1.8.2
  flutter_spinkit: ^5.1.0
  #esc_pos_bluetooth: ^0.4.1
  #flutter_bluetooth_basic: ^0.1.7
  flutter_switch: ^0.3.2
  #flutter_scan_bluetooth: ^2.1.2
  #conditional_builder_null_safety: ^0.0.6
  intl: ^0.17.0
  bluetooth_print: ^4.0.1
  #flutter_blue: ^0.8.0
  blue_thermal_printer: ^1.2.3
  #rxdart: ^0.27.2
  esc_pos_utils_plus: ^2.0.1+6
  flutter_blue_plus: ^1.3.1
  qr_flutter: ^4.0.0
  image: ^3.2.2
  url_launcher: ^6.0.0
  scroll_snap_list: ^0.9.1
  permission_handler: ^10.2.0
  app_settings: ^4.1.8

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.11.0"

有人能帮我解决这个问题吗。谢谢...
我已经尝试了这么多的解决方案,可在堆栈溢出,但无法克服的错误。

2fjabf4q

2fjabf4q1#

用途

<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />

不要忘记在清单顶部添加xmlns

xmlns:tools="http://schemas.android.com/tools"

相关问题