【问题标题】:Android App Bundle build error: reserved fileAndroid App Bundle 构建错误:保留文件
【发布时间】:2022-02-16 17:24:14
【问题描述】:

新的应用发布格式 Android App Bundle 是一种改进的应用打包方式。 Android App Bundle 让您可以更轻松地以更小的应用程序提供出色的体验,从而支持当今可用的各种 Android 设备。您无需重构代码即可开始从较小的应用程序中受益。

我在尝试构建我的应用 Android Bundle 时遇到此错误:

文件 'root/AndroidManifest.xml' 使用保留的文件或目录名称 'AndroidManifest.xml'。

APK 生成工作正常

这是我的项目文件结构:

这是我的 AndroidManifest.xml,位于 {ProjectName}/app/src/main 下:

<?xml version="1.0" encoding="utf-8"?>
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                package="com.XXXX.XXXX"
                android:installLocation="auto">

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

                <!-- These permissions are strongly recommended and will result in higher performance -->
                <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
                <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
                <uses-permission android:name="android.permission.VIBRATE" />

                <application
                    android:name="com.app.webview.Application"
                    android:allowBackup="true"
                    android:icon="@mipmap/ic_launcher"
                    android:label="@string/app_name"
                    android:supportsRtl="true"
                    android:theme="@style/AppTheme"
                    android:hardwareAccelerated="true">
                    <activity
                        android:name="com.app.webview.MainActivity"
                        android:configChanges="keyboardHidden|orientation|screenSize"
                        android:label="@string/app_name"
                        android:launchMode="singleTask">
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />

                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>

                        <!-- Universal APP Link -->
                        <intent-filter>
                            <action android:name="android.intent.action.VIEW" />

                            <category android:name="android.intent.category.DEFAULT" />
                            <category android:name="android.intent.category.BROWSABLE" />

                            <data android:scheme="http" />
                            <data android:scheme="https" />
                            <data android:host="@string/app_host" />
                        </intent-filter>
                    </activity>

                    <!-- Push -->
                    <!-- Services that handles incoming message -->
                    <service
                        android:name="com.app.webview.Providers.FCM.FcmListenerService">
                        <intent-filter>
                            <action android:name="com.google.firebase.MESSAGING_EVENT" />
                        </intent-filter>
                    </service>

                    <!-- Called if InstanceID token is updated -->
                    <!-- This may occur if the security of the previous token had been compromised -->
                    <service
                        android:name="com.app.webview.Providers.FCM.FcmInstanceIDListenerService"
                        android:exported="true">
                        <intent-filter>
                            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                        </intent-filter>
                    </service>

                    <!-- Facebook Config -->
                    <meta-data
                        android:name="com.facebook.sdk.ApplicationId"
                        android:value="@string/id_facebook" />

                    <activity
                        android:name="com.facebook.FacebookActivity"
                        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                        android:label="@string/app_name"
                        android:theme="@android:style/Theme.Translucent.NoTitleBar"
                        tools:replace="android:theme" />

                    <provider
                        android:name="com.facebook.FacebookContentProvider"
                        android:authorities="@string/facebook_provider"
                        android:exported="true"
                        tools:replace="android:authorities" />

                    <!-- Fabric -->
                    <meta-data
                        android:name="io.fabric.ApiKey"
                        android:value="XXXX" />
                </application>  
            </manifest>

【问题讨论】:

  • 如果那是您的实际清单,为什么它在子目录下?
  • 它位于 modulefolder/src/main/AndroidManifest.xml 下
  • 你是如何添加这个模块的?您只是将文件夹复制到当前源中吗?
  • 不,我正在等待 Google 方面的修复并使用 APK
  • 这里有同样的问题。 APK 正在构建,但不是 Bundle。

标签: android android-bundle


【解决方案1】:

在 Facebook 修复 SDK 之前,一个更简单的修复方法是将其添加到应用 build.gradle 的 android { } 块中的 packagingOptions:

android {
   packagingOptions {
      exclude 'AndroidManifest.xml' //This fixes a bug in FAN 5.0.1
   }
}

我只能在构建 App Bundle 时确认这是否有效,我不知道常规 APK。

【讨论】:

  • 太棒了,我有大量的依赖项,我不知道是什么阻止了我构建 App Bundle,因为这个 AndroidManifest.xml 错误。我花了几个小时调查、降级依赖等。最后我添加了这个,现在我可以构建 App Bundle(这只是一个快速修复,但仍然有效)。谢谢!!
  • Facebook 已经更新了 SDK 来解决这个 bug,你应该更新到 5.1.0 或更高版本。
  • 你是个天使,这段代码就像一个魅力。谢谢!!
【解决方案2】:

就我而言,我的错误是由

引起的

com.facebook.android:audience-network-sdk

我只是将 Audience-network-sdk 从 5.0.0 降级到 4.99.3 并且一切都开始正常工作。希望对您有所帮助。

更新: 正如 Sebastian 所说,现在您可以将 Audience-network-sdk 从 5.0.0 更新到 5.1.0。

【讨论】:

    【解决方案3】:

    自 10 月 31 日起,Facebook 发布了 Audience Network SDK 5.1 版。使用

    实现'com.facebook.android:audience-network-sdk:5.1.0'

    为我解决了这个问题。

    【讨论】:

      【解决方案4】:

      如果我正确读取文件树,则您的 AndroidManifest.xml 文件位于 res 文件夹中,这可能是您看到错误的原因。尝试将文件放入{ProjectName}/app/src/main 并重建项目。

      【讨论】:

      • 它不存在,在文件树中看起来像是在里面但在{ProjectName}/app/src/main
      • IntelliJ 的树形视图很奇怪。展开箭头实际上与父文件夹对齐。
      • 如果是这种情况,您能分享一下清单文件中的内容吗?那里可能有错误。
      • mainfest 文件看起来不错。没有错误/放置标签或类似的东西。您是否尝试过将项目与文件系统重新同步? Android Studio 中的快捷键是 Ctrl + Alt + Y
      【解决方案5】:

      我遇到了同样的错误。在获得工作版本之前必须更改一些内容。对我来说是:

      1. 将 facebook Audience-network-sdk 从 5.0.0 降级到 4.28.2
      2. 将 okio 从 2.1.0 降级到 2.0.0
      3. 更新 okio、okhttp 和改造的 proguard 配置
      4. 不使用 R8

      希望对你有帮助。

      【讨论】:

        【解决方案6】:

        回答晚了,但我遇到了同样的问题,但情况略有不同。我没有使用上面提到的 facebook 库,但它是其他一些库,由于构建的信息较少,我无法弄清楚。

        我有一个子模块(比如module1),其中包括另一个库,该库还具有许多依赖项。所以我说,

        packagingOptions {
                exclude 'AndroidManifest.xml'
        }
        

        module1build.gradle中然后问题就解决了。

        仅仅写下这个答案来传达appbuild.gradle可能无法解决所有情况的问题。

        非常感谢@Jason 指出正确的方向。

        【讨论】:

          【解决方案7】:

          对于那些知道为什么 facebook 库有这样的问题的人:

          您可以从maven respository下载aar文件,然后将其拖入Android Studio并展开classes.jar。您会看到classes.jar 中有一个清单文件。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-09-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-02-13
            • 2020-01-27
            • 1970-01-01
            相关资源
            最近更新 更多