如何修复 AndroidManifest.xml:30:标签 <service> 属性名称包含无效字符“{”。在统一构建 Android 应用程序时

问题描述 投票:0回答:1

我在尝试从 Unity 构建 Android 应用程序时遇到错误,这是输出:

CommandInvokationFailure: Failed to re-package resources.
C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.3\aapt.exe package --auto-add-overlay -v -f -m -J "gen" -M "AndroidManifest.xml" -S "res" -I "C:/Program Files (x86)/Android/android-sdk\platforms\android-29\android.jar" -F bin/resources.ap_ --extra-packages com.nirvana.youque:com.nirvana.android -S "C:\Users\yudhi_trendhi\Downloads\Game1\u3d_proj\Temp\StagingArea\android-libraries\a17-release\res" -S "C:\Users\yudhi_trendhi\Downloads\Game1\u3d_proj\Temp\StagingArea\android-libraries\NirvanaAndroid\res"

stderr[
AndroidManifest.xml:30: Tag <service> attribute name has invalid character '{'.
AndroidManifest.xml:32: Tag <receiver> attribute name has invalid character '{'.
]

我已经检查了

AndroidManifest.xml
合并,这是第 30-32 行的代码:

    <service android:enabled="true" android:exported="false" android:name="${applicationId}.PushService" android:process=":mult">
    </service>
    <receiver android:name="${applicationId}.PushReceiver">

这是

${applicationId}
是触发错误,但是当我搜索如何修复它时,我发现https://stackoverflow.com/a/57075087/8943429发布该状态

仅清单支持诸如 ${applicationId} 之类的清单占位符,不支持任意其他 XML 文件,例如快捷方式元数据资源。

所以我假设

${applicationId}
应该可以在
AndroidManifest.xml
中声明,我应该怎么做才能摆脱这个问题?

android unity-game-engine android-manifest
1个回答
0
投票

在你的 build.gradle 文件中:

android {
    defaultConfig {
        // Define a build configuration field for the application ID
        buildConfigField "String", "APPLICATION_ID", "\"com.example.myapp\""
    }
}

然后在你的 AndroidManifest.xml 中:

<service android:enabled="true"
        android:exported="false"
        android:name="${applicationId}.PushService"
        android:process=":mult">
</service>

<receiver android:name="${applicationId}.PushReceiver">
    <!-- Receiver configuration -->
</receiver>

在此示例中,

${applicationId}
将替换为构建过程中在
build.gradle
文件中定义的实际应用程序 ID。

© www.soinside.com 2019 - 2024. All rights reserved.