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

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

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任务期间,我遇到了以下错误:


这个版本的亮点有:
- Kotlin DSL的改进
- 配置缓存的第一次构建中的细粒度并行性
- 可配置的Gradle用户主目录缓存清理

更多详情请参阅https://docs.gradle.org/8.0.1/release-notes.html

正在启动Gradle Daemon(后续构建将更快)
Gradle 8.0.1
Gradle 8.0.1

> 配置项目:gradle-plugin
在detachedConfiguration1中解析org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 
在:classpath中解析org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 
位于:的项目react-native-gradle-plugin要么不是Android应用项目,要么构建版本尚未设置为覆盖。跳过...
> 配置项目:
位于:的项目AppCenterTest要么不是Android应用项目,要么构建版本尚未设置为覆盖。跳过...

FAILURE: 构建失败。

* 出现了什么问题:
配置根项目'AppCenterTest'时出现问题。
> 无法确定null的依赖项。
   > 无法解析配置':classpath'的所有任务依赖项。
      > 找不到com.android.tools.build:gradle:。
        所需的是:
            项目:
      > 无法解析com.facebook.react:react-native-gradle-plugin。
        所需的是:
            项目:
         > 找不到匹配的项目:gradle-plugin的变体。消费者配置为在运行时使用与Java 8兼容、打包为jar文件的库及其外部声明的依赖项,以及带有值'8.0.1'的属性'org.gradle.plugin.api-version',但:
             - 变体'apiElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个打包为jar文件的库及其外部声明的依赖项:
                 - 不兼容,因为此组件声明了一个用于编译时使用的组件,与Java 11兼容,而消费者需要一个用于运行时使用的组件,与Java 8兼容
                 - 其他兼容属性:
                     - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1')
             - 变体'mainSourceElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个组件及其外部声明的依赖项:
                 - 不兼容,因为此组件声明了一个类别为'verification'的组件,而消费者需要一个库
                 - 其他兼容属性:
                     - 不提供关于其目标Java版本的信息(需要与Java 8兼容)
                     - 不提供关于其元素的信息(需要将它们打包为jar文件)
                     - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1')
                     - 不提供关于其使用方式的信息(需要运行时)
             - 变体'runtimeElements'的能力com.facebook.react:react-native-gradle-plugin:unspecified声明了一个用于运行时使用的库,打包为jar文件,及其外部声明的依赖项:
                 - 不兼容,因为此组件声明了一个与Java 11兼容的组件,而消费者需要一个与Java 8兼容的组件
                 - 其他兼容属性:
                     - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1')
             - 变体'testResultsElementsForTest'的能力com.facebook.react:react-native-gradle-plugin:unspecified:
                 - 不兼容,因为此组件声明了一个类别为'verification'的组件,而消费者需要一个库
                 - 其他兼容属性:
                     - 不提供关于如何找到其依赖项的信息(需要其外部声明的依赖项)
                     - 不提供关于其目标Java版本的信息(需要与Java 8兼容)
                     - 不提供关于其元素的信息(需要将它们打包为jar文件)
                     - 不提供关于org.gradle.plugin.api-version的信息(需要'8.0.1')
                     - 不提供关于其使用方式的信息(需要运行时)

* 尝试:
> 使用--stacktrace选项运行以获取堆栈跟踪。
> 使用--info或--debug选项运行以获取更多日志输出。
> 使用--scan运行以获取完整的洞察。

* 获取更多帮助,请访问https://help.gradle.org

BUILD FAILED in 2m 36s
Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
    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)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
##[error]Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
    at maybeClose (internal/child_process.js:920:16)
    at Socket.<anonymous> (internal/child_process.js:351:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:509:12)
##[section]Finishing: Gradle Task

这是npx react-native info的结果:

系统:
  操作系统:macOS 13.4.1
  CPU:(8) arm64 Apple M1
  内存:63.02 MB / 16.00 GB
  Shell:
    版本:"5.9"
    路径:/bin/zsh
二进制文件:
  Node:
    版本:18.16.1
    路径:~/.nvm/versions/node/v18.16.1/bin/node
  Yarn:
    版本:1.22.19
    路径:~/.nvm/versions/node/v18.16.1/bin/yarn
  npm:
    版本:9.5.1
    路径:~/.nvm/versions/node/v18.16.1/bin/npm
  Watchman:
    版本:2023.07.10.00
    路径:/opt/homebrew/bin/watchman
管理器:
  CocoaPods:
    版本:1.12.1
    路径:/Users/dev/.asdf/shims/pod
SDK:
  iOS SDK:
    平台:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:未找到
IDE:
  Android Studio:2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    版本:14.3/14E222b
    路径:/usr/bin/xcodebuild
语言:
  Java:
    版本:19.0.2
    路径:/usr/bin/javac
  Ruby:
    版本:2.7.5
    路径:/Users/dev/.asdf/shims/ruby
npm软件包:
  "@react-native-community/cli":未找到
  react:
    已安装:18.2.0
    需要:18.2.0
  react-native:
    已安装:0.72.3
    需要:0.72.3
  react-native-macos:未找到
npm全局软件包:
  "*react-native*":未找到
Android:
  hermesEnabled:true
  newArchEnabled:false
iOS:
  hermesEnabled:true
  newArchEnabled:false

这是原始项目,我没有添加任何库。
在本地上,./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:


Here are the highlights of this release:
 - Improvements to the Kotlin DSL
 - Fine-grained parallelism from the first build with configuration cache
 - Configurable Gradle user home cache cleanup

For more details see https://docs.gradle.org/8.0.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
Gradle 8.0.1
Gradle 8.0.1

> Configure project :gradle-plugin
Resolved org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 in detachedConfiguration1 
Resolved org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.7.22 in :classpath 
Project react-native-gradle-plugin at : is either no Android app project or build version has not been set to override. Skipping...

> Configure project :
Project AppCenterTest at : is either no Android app project or build version has not been set to override. Skipping...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'AppCenterTest'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.android.tools.build:gradle:.
        Required by:
            project :
      > Could not resolve com.facebook.react:react-native-gradle-plugin.
        Required by:
            project :
         > 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:
             - Variant 'apiElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
                 - 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
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
             - Variant 'mainSourceElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a component, and its dependencies declared externally:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
                     - Doesn't say anything about its usage (required runtime)
             - 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:
                 - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
             - Variant 'testResultsElementsForTest' capability com.facebook.react:react-native-gradle-plugin:unspecified:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1')
                     - Doesn't say anything about its usage (required runtime)

* 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 2m 36s
Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
    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)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
##[error]Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1
    at maybeClose (internal/child_process.js:920:16)
    at Socket.<anonymous> (internal/child_process.js:351:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:509:12)
##[section]Finishing: Gradle Task

Here's the result from npx react-native info

System:
  OS: macOS 13.4.1
  CPU: (8) arm64 Apple M1
  Memory: 63.02 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: ~/.nvm/versions/node/v18.16.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.16.1/bin/yarn
  npm:
    version: 9.5.1
    path: ~/.nvm/versions/node/v18.16.1/bin/npm
  Watchman:
    version: 2023.07.10.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/dev/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.3/14E222b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 19.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/dev/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.3
    wanted: 0.72.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  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:

确定