为啥我的 Flutter 应用程序在执行时没有构建?

Posted

技术标签:

【中文标题】为啥我的 Flutter 应用程序在执行时没有构建?【英文标题】:Why my Flutter app is not building while executing?为什么我的 Flutter 应用程序在执行时没有构建? 【发布时间】:2022-01-14 13:44:27 【问题描述】:

我一直在尝试构建一个颤振应用程序。但是在导出/构建它时出现错误。构建时的错误消息:

Launching lib\main.dart on android SDK built for x86 in debug mode...
lib\main.dart:1
C:\dev\bmi\android\app\src\main\AndroidManifest.xml Error:
    Package name 'BMI' at position AndroidManifest.xml:2:5-18 should contain at least one '.' (dot) character

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : Package name 'BMI' at position AndroidManifest.xml:2:5-18 should contain at least one '.' (dot) character


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 21s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

andriodmainifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="BMI">
    <!-- 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"/>
</manifest>

【问题讨论】:

在这里分享你的安卓清单文件 @Suganya我已经在我的问题中添加了文件。 【参考方案1】:

错误出现在清单文件中给出的包名上。 您可以将包名称添加为 com.bmi 等。 请参考下面从我的项目中添加的清单文件。

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            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>
        <meta-data
            android:name="io.flutter.network-policy"
            android:resource="@xml/network_security_config" />
        <!-- 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>

【讨论】:

以上是关于为啥我的 Flutter 应用程序在执行时没有构建?的主要内容,如果未能解决你的问题,请参考以下文章

Flutter:为啥我的构建器在 Web 服务调用后没有重新加载?

为啥我在构建 Flutter Web 时会出现白屏

为啥在使用 Flutter 模块构建 iOS 原生应用时修复“Frameworks/Flutter.framework: Permission denied”?

为啥我在构建项目时出现 Flutter gradle 错误?

为啥 Flutter 编译器告诉我我的应用程序不存在?

为啥 Flutter iOS 构建失败?