首页 > 解决方案 > Android Manifest 是否影响 Flutter 中的构建

问题描述

这是我关于堆栈溢出的第一篇文章,所以请放心。自从我制作一个应用程序以来也已经有几年了,所以我的概念理解已经不像以前那样了。

我目前的目标是为我的移动应用程序设置 RTSP 服务。

我无法获取用于连接互联网上任何内容的插件,因此我的第一个调试步骤是确保AndroidManifest.xml文件正常。

下面,是我的AndroidManifest.xml文件。

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ad_hoc.ad_hoc">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   <application
        android:label="ad_hoc"
        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>

如果我的清单文件中有一些错误,颤振构建会受到影响吗?我能够运行该应用程序,但我不确定我的互联网权限是否有效,因此我不确定。

以下是我在清单文件中遇到的以下错误:

“Unresolved class MainActivity”和“Attribute android:launchMode is not allowed here”

多个属性出现“此处不允许”错误。我应该解决这些问题还是离开?我已经建立了新项目,看看这个问题是否仍然存在并且确实存在。不知道如何解决这个问题。

对于未解决的类,我不确定如何让清单识别我在main.dart.xml文件中使用的主要活动。主节点的名称Activity不是MainActivity

任何指针/帮助将不胜感激。

我可以做任何简单的测试来确保我的应用程序能够连接到互联网吗?

所以总结一下我的问题,尽管我在清单文件中有这些问题,但是否会授予互联网权限?

谢谢!

标签: androidflutter

解决方案


是的,当在 android 设备上构建或运行时,清单显然会对运行应用程序产生影响。但是 - 如果您AndroidManifest.xml真的包含这些错误,则应用程序将不会首先启动。

我的猜测是你要么看错了,AndroidManifest.xml要么你的 Android Studio 有问题。首先确保您实际上在 android 模块中,而不是在根颤振项目中。IE。不在myproject/但在myproject/android(在 Android Studio 中,您可以使用“工具 -> Flutter -> 在 Android Studio 中打开以进行编辑”)。

如果您确实在正确的模块中,请尝试从从您的 Android 应用程序打开的 Android Studio 内部运行,而不是从根文件夹中运行。这可能会给您更多错误消息。

另外:默认情况下debug,默认 Flutter 项目模板中的 android manifest 的变体将包括 internet 权限。因此,如果您不更改任何内容,则调试版本可能会正常工作,但发布版本缺少 Internet 权限。


推荐阅读