权限在颤振发布 apk 中不起作用

Posted

技术标签:

【中文标题】权限在颤振发布 apk 中不起作用【英文标题】:Permissions not working in flutter release apk 【发布时间】:2021-08-18 10:36:23 【问题描述】:

我是 Flutter 的新手。我正在创建一个简单的应用程序,在其中我从 Web api 获取数据并访问相机以扫描 QR 码。当我运行调试应用程序时它工作正常但是当我构建发布 apk 时它不能工作而不是相机和互联网即使我已经在 androidManifest.xml 文件中设置了权限。这是我的 AndroidManifest 文件代码:-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.nic.rajshaladarpan.filetrackingsystem">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

   <application
        android:label="File Tracking System"
        android:icon="@mipmap/ic_launcher">
        <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">
            <!-- 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>
</manifest>

我的 pubspec.ymal 文件代码在这里:-

name: filetrackingsystem
description: A new Flutter application.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In ios, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

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
  qrscan: ^0.2.22
  image_gallery_saver: ^1.1.0
  image_picker: ^0.6.1+4
  permission_handler: 7.1.0
  crypto: ^3.0.1
  http: ^0.13.3
  shared_preferences: ^2.0.6
  progress_dialog: ^1.2.4
  intl: ^0.16.0
  modal_progress_hud_nsn: ^0.1.0-nullsafety-0
  group_radio_button: ^1.1.0

#  permission_handler: ^5.0.1+1

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  assets:
    - splash.jpg
    - login_bg.jpg
    - all_screen_bg.jpg
    - navigation_icon.png
    - filetracking.png
    - user.png
    - file_black.png
    - file_yellow.png
    - copy.png
    - restbg.jpg
    - headerbg.png
    - back_arrow.png
    - qr_icon.png
  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

所有互联网访问问题的答案都有相同的解决方案,在创建发布版本之前在 AndroidManifest 文件中添加互联网权限,但这些解决方案对我不起作用,所以我在这里问这个问题。请帮帮我

【问题讨论】:

【参考方案1】:

请注意,您还必须在发布版本AndroidManifest中添加所有必要的权限,而不仅仅是在调试AndroidManifest中, 但在你的问题中,你没有提到你在哪个文件中添加了权限

【讨论】:

感谢您的回复。我在 myproject/android/app/src/main/AndroidManifest.xml 文件中添加权限。

以上是关于权限在颤振发布 apk 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

Flutter apk 在 android 设备中不起作用

颤振补间基本动画在“FutureBuilder”中不起作用

为啥这个切换按钮在颤振 - 飞镖中不起作用?

滑动以返回在 ios 中的颤振 webview 中不起作用

颤振热重新加载在android studio(mac)中不起作用

Firebase 注销在颤振应用程序中不起作用