AppCenter React Native 构建遇到 Gradle 错误

问题描述 投票:0回答:1

最近,我将我的 React Native Expo 构建的 GitLab 存储库与 AppCenter 链接起来,这样我就可以开始构建它、测试它并进行部署。起初,AppCenter甚至没有识别它,我发现我必须执行命令“expo pop”,所以它有一个Android文件夹。链接成功后,我去构建它,但构建出现 Gradle 错误。除了 App.js 之外,React Native 项目上绝对没有任何代码,我创建它只是为了练习构建和部署。

这是 Gradle 错误,每当我尝试使用虚拟机构建它时:

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 ReVele 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 'ReVele'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.android.tools.build:gradle:x.y.z.
        Searched in the following locations:
          - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/x.y.z/gradle-x.y.z.pom
          - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/x.y.z/gradle-x.y.z.pom
        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 28s
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)
    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)
##[error]Error: /Users/runner/work/1/s/android/gradlew failed with return code: 1

我什至无法在我的计算机上运行该项目。

我尝试更改 Android 存档上的 Gradle 版本,但无论如何都不起作用。

react-native gradle build visual-studio-app-center
1个回答
0
投票

同样的事情也发生在我身上,我可以通过在 AppCenter 构建配置中添加

JAVA_HOME: $(JAVA_HOME_11_X64)
环境变量来修复它,如本答案中所建议的:https://stackoverflow.com/a/76914173/1602584

© www.soinside.com 2019 - 2024. All rights reserved.