React Native(0.72.3)在App Center上构建Android失败。

huangapple go评论164阅读模式
英文:

React Native(0.72.3) Android build fails at App Center

问题

我将为您翻译以下内容:

我将AppCenter添加到初始的React Native项目中,但在构建Android应用程序时遇到了错误。

我按照以下步骤进行操作:

  1. 在AppCenter上为Android和React Native创建一个新项目。
  2. 使用npx react-native init AppCenterTest创建一个新项目。
  3. 按照App Center的步骤进行操作:
    • yarn add appcenter appcenter-analytics appcenter-crashes --save-exact
    • 在android/app/src/main/assets/目录下创建一个名为appcenter-config.json的新文件,并填入我的密钥。
    • 推送到GitHub。
  4. 设置构建配置。
  5. 保存并运行构建。

在构建过程中的Gradle任务期间,我遇到了以下错误:

  1. 这个版本的亮点有:
  2. - Kotlin DSL的改进
  3. - 配置缓存的第一次构建中的细粒度并行性
  4. - 可配置的Gradle用户主目录缓存清理
  5. 更多详情请参阅https://docs.gradle.org/8.0.1/release-notes.html
  6. 正在启动Gradle Daemon(后续构建将更快)
  7. Gradle 8.0.1
  8. Gradle 8.0.1
  9. > 配置项目:gradle-plugin
  10. detachedConfiguration1中解析org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22
  11. 在:classpath中解析org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22
  12. 位于:的项目react-native-gradle-plugin要么不是Android应用项目,要么构建版本尚未设置为覆盖。跳过...
  13. > 配置项目:
  14. 位于:的项目AppCenterTest要么不是Android应用项目,要么构建版本尚未设置为覆盖。跳过...
  15. FAILURE: 构建失败。
  16. * 出现了什么问题:
  17. 配置根项目'AppCenterTest'时出现问题。
  18. > 无法确定null的依赖项。
  19. > 无法解析配置':classpath'的所有任务依赖项。
  20. > 找不到com.android.tools.build:gradle:。
  21. 所需的是:
  22. 项目:
  23. > 无法解析com.facebook.react:react-native-gradle-plugin
  24. 所需的是:
  25. 项目:
  26. > 找不到匹配的项目:gradle-plugin的变体。消费者配置为在运行时使用与Java 8兼容、打包为jar文件的库及其外部声明的依赖项,以及带有值'8.0.1'的属性'org.gradle.plugin.api-version',但:
  27. - 变体'apiElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个打包为jar文件的库及其外部声明的依赖项:
  28. - 不兼容,因为此组件声明了一个用于编译时使用的组件,与Java 11兼容,而消费者需要一个用于运行时使用的组件,与Java 8兼容
  29. - 其他兼容属性:
  30. - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1'
  31. - 变体'mainSourceElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个组件及其外部声明的依赖项:
  32. - 不兼容,因为此组件声明了一个类别为'verification'的组件,而消费者需要一个库
  33. - 其他兼容属性:
  34. - 不提供关于其目标Java版本的信息(需要与Java 8兼容)
  35. - 不提供关于其元素的信息(需要将它们打包为jar文件)
  36. - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1'
  37. - 不提供关于其使用方式的信息(需要运行时)
  38. - 变体'runtimeElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个用于运行时使用的库,打包为jar文件,及其外部声明的依赖项:
  39. - 不兼容,因为此组件声明了一个与Java 11兼容的组件,而消费者需要一个与Java 8兼容的组件
  40. - 其他兼容属性:
  41. - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1'
  42. - 变体'testResultsElementsForTest'的能力com.facebook.react:react-native-gradle-plugin:unspecified
  43. - 不兼容,因为此组件声明了一个类别为'verification'的组件,而消费者需要一个库
  44. - 其他兼容属性:
  45. - 不提供关于如何找到其依赖项的信息(需要其外部声明的依赖项)
  46. - 不提供关于其目标Java版本的信息(需要与Java 8兼容)
  47. - 不提供关于其元素的信息(需要将它们打包为jar文件)
  48. - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1'
  49. - 不提供关于其使用方式的信息(需要运行时)
  50. * 尝试:
  51. > 使用--stacktrace选项运行以获取堆栈跟踪。
  52. > 使用--info或--debug选项运行以获取更多日志输出。
  53. > 使用--scan运行以获取完整的洞察。
  54. * 获取更多帮助,请访问https://help.gradle.org
  55. BUILD FAILED in 2m 36s
  56. Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
  57. at ChildProcess.<anonymous> (/Users/runner/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/1.128.0/node_modules/vsts-task-lib/toolrunner.js:569:30)
  58. at emitTwo (events.js:106:13)
  59. at ChildProcess.emit (events.js:191:7)
  60. ##[error]Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
  61. at maybeClose (internal/child_process.js:920:16)
  62. at Socket.<anonymous> (internal/child_process.js:351:11)
  63. at emitOne (events.js:96:13)
  64. at Socket.emit (events.js:188:7)
  65. at Pipe._handle.close [as _onclose] (net.js:509:12)
  66. ##[section]Finishing: Gradle Task

这是npx react-native info的结果:

  1. 系统:
  2. 操作系统:macOS 13.4.1
  3. CPU:(8) arm64 Apple M1
  4. 内存:63.02 MB / 16.00 GB
  5. Shell
  6. 版本:"5.9"
  7. 路径:/bin/zsh
  8. 二进制文件:
  9. Node
  10. 版本:18.16.1
  11. 路径:~/.nvm/versions/node/v18.16.1/bin/node
  12. Yarn
  13. 版本:1.22.19
  14. 路径:~/.nvm/versions/node/v18.16.1/bin/yarn
  15. npm
  16. 版本:9.5.1
  17. 路径:~/.nvm/versions/node/v18.16.1/bin/npm
  18. Watchman
  19. 版本:2023.07.10.00
  20. 路径:/opt/homebrew/bin/watchman
  21. 管理器:
  22. CocoaPods
  23. 版本:1.12.1
  24. 路径:/Users/dev/.asdf/shims/pod
  25. SDK
  26. iOS SDK
  27. 平台:
  28. - DriverKit 22.4
  29. - iOS 16.4
  30. - macOS 13.3
  31. - tvOS 16.4
  32. - watchOS 9.4
  33. Android SDK:未找到
  34. IDE
  35. Android Studio2022.2 AI-222.4459.24.2221.10121639
  36. Xcode
  37. 版本:14.3/14E222b
  38. 路径:/usr/bin/xcodebuild
  39. 语言:
  40. Java
  41. 版本:19.0.2
  42. 路径:/usr/bin/javac
  43. Ruby
  44. 版本:2.7.5
  45. 路径:/Users/dev/.asdf/shims/ruby
  46. npm软件包:
  47. "@react-native-community/cli":未找到
  48. react
  49. 已安装:18.2.0
  50. 需要:18.2.0
  51. react-native
  52. 已安装:0.72.3
  53. 需要:0.72.3
  54. react-native-macos:未找到
  55. npm全局软件包:
  56. "*react-native*":未找到
  57. Android
  58. hermesEnabledtrue
  59. newArchEnabledfalse
  60. iOS
  61. hermesEnabledtrue
  62. newArchEnabledfalse

这是原始项目,我没有添加任何库。
在本地上,./gradlew assembleRelease可以正常工作,我也能够使用Android Studio构建APK文件。

英文:

I added AppCenter to the initial React Native Project and I got the error while building the Android app.

I followed these steps:

  1. Create a new project for Android and React Native at AppCenter.
  2. Created a new project using npx react-native init AppCenterTest.
  3. Followed the steps from App Center.
  • yarn add appcenter appcenter-analytics appcenter-crashes --save-exact
  • Create a new file with the filename appcenter-config.json in android/app/src/main/assets/ with my secret key
  • Push to github
  1. Set build configuration
    React Native(0.72.3)在App Center上构建Android失败。
  2. Save and run build

During the Gradle task in the build process, I get the following error:

  1. Here are the highlights of this release:
  2. - Improvements to the Kotlin DSL
  3. - Fine-grained parallelism from the first build with configuration cache
  4. - Configurable Gradle user home cache cleanup
  5. For more details see https://docs.gradle.org/8.0.1/release-notes.html
  6. Starting a Gradle Daemon (subsequent builds will be faster)
  7. Gradle 8.0.1
  8. Gradle 8.0.1
  9. > Configure project :gradle-plugin
  10. Resolved org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 in detachedConfiguration1
  11. Resolved org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 in :classpath
  12. Project react-native-gradle-plugin at : is either no Android app project or build version has not been set to override. Skipping...
  13. > Configure project :
  14. Project AppCenterTest at : is either no Android app project or build version has not been set to override. Skipping...
  15. FAILURE: Build failed with an exception.
  16. * What went wrong:
  17. A problem occurred configuring root project 'AppCenterTest'.
  18. > Could not determine the dependencies of null.
  19. > Could not resolve all task dependencies for configuration ':classpath'.
  20. > Could not find com.android.tools.build:gradle:.
  21. Required by:
  22. project :
  23. > Could not resolve com.facebook.react:react-native-gradle-plugin.
  24. Required by:
  25. project :
  26. > No matching variant of project :gradle-plugin was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0.1' but:
  27. - Variant 'apiElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
  28. - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
  29. - Other compatible attribute:
  30. - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
  31. - Variant 'mainSourceElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a component, and its dependencies declared externally:
  32. - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
  33. - Other compatible attributes:
  34. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  35. - Doesn't say anything about its elements (required them packaged as a jar)
  36. - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
  37. - Doesn't say anything about its usage (required runtime)
  38. - Variant 'runtimeElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
  39. - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
  40. - Other compatible attribute:
  41. - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
  42. - Variant 'testResultsElementsForTest' capability com.facebook.react:react-native-gradle-plugin:unspecified:
  43. - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
  44. - Other compatible attributes:
  45. - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
  46. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  47. - Doesn't say anything about its elements (required them packaged as a jar)
  48. - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
  49. - Doesn't say anything about its usage (required runtime)
  50. * Try:
  51. > Run with --stacktrace option to get the stack trace.
  52. > Run with --info or --debug option to get more log output.
  53. > Run with --scan to get full insights.
  54. * Get more help at https://help.gradle.org
  55. BUILD FAILED in 2m 36s
  56. Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
  57. at ChildProcess.<anonymous> (/Users/runner/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/1.128.0/node_modules/vsts-task-lib/toolrunner.js:569:30)
  58. at emitTwo (events.js:106:13)
  59. at ChildProcess.emit (events.js:191:7)
  60. ##[error]Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
  61. at maybeClose (internal/child_process.js:920:16)
  62. at Socket.<anonymous> (internal/child_process.js:351:11)
  63. at emitOne (events.js:96:13)
  64. at Socket.emit (events.js:188:7)
  65. at Pipe._handle.close [as _onclose] (net.js:509:12)
  66. ##[section]Finishing: Gradle Task

Here's the result from npx react-native info

  1. System:
  2. OS: macOS 13.4.1
  3. CPU: (8) arm64 Apple M1
  4. Memory: 63.02 MB / 16.00 GB
  5. Shell:
  6. version: "5.9"
  7. path: /bin/zsh
  8. Binaries:
  9. Node:
  10. version: 18.16.1
  11. path: ~/.nvm/versions/node/v18.16.1/bin/node
  12. Yarn:
  13. version: 1.22.19
  14. path: ~/.nvm/versions/node/v18.16.1/bin/yarn
  15. npm:
  16. version: 9.5.1
  17. path: ~/.nvm/versions/node/v18.16.1/bin/npm
  18. Watchman:
  19. version: 2023.07.10.00
  20. path: /opt/homebrew/bin/watchman
  21. Managers:
  22. CocoaPods:
  23. version: 1.12.1
  24. path: /Users/dev/.asdf/shims/pod
  25. SDKs:
  26. iOS SDK:
  27. Platforms:
  28. - DriverKit 22.4
  29. - iOS 16.4
  30. - macOS 13.3
  31. - tvOS 16.4
  32. - watchOS 9.4
  33. Android SDK: Not Found
  34. IDEs:
  35. Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  36. Xcode:
  37. version: 14.3/14E222b
  38. path: /usr/bin/xcodebuild
  39. Languages:
  40. Java:
  41. version: 19.0.2
  42. path: /usr/bin/javac
  43. Ruby:
  44. version: 2.7.5
  45. path: /Users/dev/.asdf/shims/ruby
  46. npmPackages:
  47. "@react-native-community/cli": Not Found
  48. react:
  49. installed: 18.2.0
  50. wanted: 18.2.0
  51. react-native:
  52. installed: 0.72.3
  53. wanted: 0.72.3
  54. react-native-macos: Not Found
  55. npmGlobalPackages:
  56. "*react-native*": Not Found
  57. Android:
  58. hermesEnabled: true
  59. newArchEnabled: false
  60. iOS:
  61. hermesEnabled: true
  62. newArchEnabled: false

It's the raw project and I didn't add any libraries.
./gradlew assembleRelease works fine on local and also I was able to build an APK using Android Studio.
1: https://i.stack.imgur.com/sCNOr.png

答案1

得分: 2

JDK11已默认安装。只需将环境变量JAVA_HOME设置为$(JAVA_HOME_11_X64)。
React Native(0.72.3)在App Center上构建Android失败。

英文:

JDK11 is installed by default. Just set environment variable JAVA_HOME to $(JAVA_HOME_11_X64)
React Native(0.72.3)在App Center上构建Android失败。

huangapple
  • 本文由 发表于 2023年8月9日 17:41:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866463.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定