Nativescript Gradle构建失败,并显示“找不到资源xml / network_security_config”

时间:2018-11-15 00:48:48

标签: angular nativescript

我有一个现有的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历史记录时,我可以看到回购中唯一更改的跟踪文件是package.json文件。我尝试恢复到我知道的上一次提交,但是仍然看到相同的错误。

以前

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

更新后

"tns-android": {
  "version": "5.0.0"
} 

使构建工作正常运行的唯一方法是,如果我从AndroidManifest.xml中删除了 android:networkSecurityConfig =“ @ xml / network_security_config” 。但是,出于开发目的,我需要这样做,因为我正在使用localhost端点,而Android需要使用https://10.0.2.2。请参阅以下文章https://medium.com/@noumaan/ssl-app-dev-a2923d5113c6

我现在很确定在平台更新期间,某些文件在导致此问题的仓库之外被修改。我尝试创建一个新的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

2 个答案:

答案 0 :(得分:2)

要使其适用于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"

答案 1 :(得分:0)

阅读“ Network security configuration”后,它说将xml文件放置在res/xml/network_security_config.xml中。所以我的完整路径是

./App_Resources/Android/src/main/res/xml/network_security_config.xml

进行此更改后,Android版本将再次运行。我仍然不确定xml文件位于以下位置时发生了什么变化,因为这以前有效:

./App_Resources/Android/xml/network_security_config.xml