Bar*_*nes 5 nativescript angular
我有一个现有的 Nativescript angular 应用程序,可以在我的 Android 模拟器上运行,没有任何问题。前几天,我使用以下命令将 tns-android 版本从 4.1.3 更新到 5.0.0:
tns platform update android
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下命令再次运行模拟器
tns run android --bundle
Run Code Online (Sandbox Code Playgroud)
但是,由于以下错误,自更新以来我一直无法使应用程序运行:
error: resource xml/network_security_config (aka org.nativescript.app:xml/network_security_config) not found.
Run Code Online (Sandbox Code Playgroud)
我的 AndroidManifest.xml 看起来像这样:
<application
android:name=...
android:debuggable="true"
android:networkSecurityConfig="@xml/network_security_config">
...
</application>
Run Code Online (Sandbox Code Playgroud)
我有一个位于 /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>
Run Code Online (Sandbox Code Playgroud)
我尝试删除平台并再次添加它,但发生了同样的错误。我还尝试删除平台并安装特定版本的 android 平台,但仍然没有运气。
当我检查我的 git 历史时,我可以看到 repo 中唯一被跟踪的文件是 package.json 文件。我尝试恢复到我知道有效的最后一次提交,但仍然看到相同的错误。
之前
"tns-android": {
"version": "4.1.3"
}
Run Code Online (Sandbox Code Playgroud)
更新后
"tns-android": {
"version": "5.0.0"
}
Run Code Online (Sandbox Code Playgroud)
让我的构建工作的唯一方法是从 AndroidManifest.xml 中删除android:networkSecurityConfig="@xml/network_security_config"。但是,出于开发目的,我需要使用它,因为我使用的是 localhost 端点,而 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
Run Code Online (Sandbox Code Playgroud)
运行 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
Run Code Online (Sandbox Code Playgroud)
小智 6
要使其适用于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" />
Run Code Online (Sandbox Code Playgroud)
对于 android@^8.1.0,您需要确保目标正确: target="app/src/main/res/xml/network_security_config.xml"
阅读“网络安全配置”后,它说将 xml 文件放入res/xml/network_security_config.xml. 所以我的完整路径是
./App_Resources/Android/src/main/res/xml/network_security_config.xml
Run Code Online (Sandbox Code Playgroud)
在我进行此更改后,Android 版本再次运行。我仍然不确定发生了什么变化,因为以前当 xml 文件位于:
./App_Resources/Android/xml/network_security_config.xml
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4895 次 |
| 最近记录: |