我在尝试从 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
中声明,我应该怎么做才能摆脱这个问题?
在你的 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。