gpt4 book ai didi

angular - Nativescript gradle 构建失败,错误为 "resource xml/network_security_config not found"

转载 作者:行者123 更新时间:2023-12-02 00:57:18 29 4
gpt4 key购买 nike

我有一个现有的 Nativescript angular 应用程序,可以在我的 Android 模拟器上运行,没有任何问题。前几天,我使用以下命令将 tns-android 版本从 4.1.3 更新到 5.0.0:

tns platform update android

然后我尝试使用以下命令再次运行模拟器
tns run android --bundle

但是,由于以下错误,自更新以来我一直无法使应用程序运行:
error: resource xml/network_security_config (aka org.nativescript.app:xml/network_security_config) not found.

我的 AndroidManifest.xml 看起来像这样:
<application
android:name=...
android:debuggable="true"
android:networkSecurityConfig="@xml/network_security_config">
...
</application>

我有一个位于/App_Resouces/Android/xml 的 network_security_config.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>

我尝试删除平台并再次添加它,但发生了同样的错误。我还尝试删除平台并安装特定版本的 android 平台,但仍然没有运气。

当我检查我的 git 历史时,我可以看到 repo 中唯一被跟踪的文件是 package.json 文件。我尝试恢复到我知道有效的最后一次提交,但仍然看到相同的错误。

以前
"tns-android": {
"version": "4.1.3"
}

更新后
"tns-android": {
"version": "5.0.0"
}

让我的构建工作的唯一方法是删除 android:networkSecurityConfig="@xml/network_security_config"来自 AndroidManifest.xml。但是,出于开发目的,我需要使用它,因为我使用的是本地主机端点,而 Android 需要使用 https://10.0.2.2 .见以下文章 https://medium.com/@noumaan/ssl-app-dev-a2923d5113c6

我很确定在这一点上,在平台更新期间,某些文件在导致此问题的 repo 之外被修改。我尝试创建一个新的 nativescript-angular 项目,然后将 network_security_config 添加到 AndroidManifest 但错误仍然发生在一个全新的项目上
tns create HelloWorld --template tns-template-blank-ng

运行 tns build 命令的完整日志文件如下所示:
Gradle build...
+ setting applicationId
+ applying user-defined configuration from /<path>/nativescript-app/app/App_Resources/Android/app.gradle
Using support library version 28.0.0
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: /<path>/nativescript-app/node_modules/tns-core-modules-widgets/platforms/android/widgets-release.aar

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
Output: /<path>/nativescript-app/platforms/a
ndroid/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/An
droidManifest.xml:22: error: resource xml/network_security_config (aka org.nativescr
ipt.app:xml/network_security_config) not found.
error: failed processing manifest.

Command: /<path>/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-osx.jar/ea8e83f954287505ed9d825341b12875/aapt2-3.2.0-4818971-osx/aapt2 link -I\
/<path>/Library/Android/sdk/platforms/android-28/android.jar\
--manifest\
/<path>/nativescript-app/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
-o\
/<path>/nativescript-app/platforms/android/app/build/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
-R\
@/<path>/nativescript-app/platforms/android/app/build/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
/<path>/nativescript-app/platforms/android/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
--custom-package\
org.nativescript.app\
-0\
apk\
--no-version-vectors\
--output-text-symbols\
/<path>/nativescript-app/platforms/android/app/build/intermediates/symbols/debug/R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.0-4818971-osx Daemon #0
Output: /<path>/nativescript-app/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml:22: AAPT: error: resource xml/network_security_config (aka org.nativescript.app:xml/network_security_config) not found.

error: failed processing manifest.
Command: /<path>/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-osx.jar/ea8e83f954287505ed9d825341b12875/aapt2-3.2.0-4818971-osx/aapt2 link -I\
/<path>/Library/Android/sdk/platforms/android-28/android.jar\
--manifest\
/<path>/nativescript-app/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
-o\
/<path>/nativescript-app/platforms/android/app/build/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
-R\
@/<path>/nativescript-app/platforms/android/app/build/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
/<path>/nativescript-app/platforms/android/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
--custom-package\
org.nativescript.app\
-0\
apk\
--no-version-vectors\
--output-text-symbols\
/<path>/nativescript-app/platforms/android/app/build/intermediates/symbols/debug/R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.0-4818971-osx Daemon #0

* 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 3s
Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed
with exit code 1.
Executing after-watch hook from /<path>/natives
cript-app/hooks/after-watch/nativescript-dev-typescript.js
Executing after-watch hook from /<path>/natives
cript-app/hooks/after-watch/nativescript-dev-webpack.js
Stopping webpack watch
Executing after-watch hook from /<path>/natives
cript-app/hooks/after-watch/nativescript-dev-typescript.js
Executing after-watch hook from /<path>/nativescript-app/hooks/after-watch/nativescript-dev-webpack.js

最佳答案

要使其适用于cordova-android@^8.1.0,请确保您具有以下配置:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />

对于 android@^8.1.0,您需要确保目标正确: target="app/src/main/res/xml/network_security_config.xml"

关于angular - Nativescript gradle 构建失败,错误为 "resource xml/network_security_config not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53310918/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com