Сбой сборки Nativescript с «ресурсом xml / network_security_config not found» - PullRequest
0 голосов
/ 15 ноября 2018

У меня есть существующее угловое приложение Nativescript, которое я смог запустить на своем эмуляторе 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>

У меня есть файл network_security_config.xml, расположенный в / App_Resouces / Android / 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"
} 

Единственный способ заставить мою сборку работать - это удалить android: networkSecurityConfig = "@ xml / network_security_config" из AndroidManifest.xml.Тем не менее, мне это нужно для целей разработки, так как я использую конечную точку 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 можно увидеть ниже:

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

1 Ответ

0 голосов
/ 15 ноября 2018

После прочтения « Конфигурация безопасности сети » говорится, что файл 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...