开发者问题收集

gradle 错误:“在项目上找不到参数 [] 的方法 useDefaultAndroidSdkVersions()”

2024-06-13
422

如何解决此错误:

在 /home/expo/workingdir/build/android 中运行“gradlew :app:assembleRelease”

Welcome to Gradle 8.3!
Here are the highlights of this release:
- Faster Java compilation
 - Reduced memory usage
 - Support for running on Java 20
For more details see https://docs.gradle.org/8.3/release-notes.html
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.3/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Task :gradle-plugin:pluginDescriptors
> Task :gradle-plugin:processResources
> Task :gradle-plugin:compileKotlin
> Task :gradle-plugin:compileJava NO-SOURCE
> Task :gradle-plugin:classes
> Task :gradle-plugin:jar
> Task :gradle-plugin:inspectClassesForKotlinIC
FAILURE: Build completed with 2 failures.
1:
Task failed with an exception.
-----------
* Where:
Build file '/home/expo/workingdir/build/node_modules/expo-application/android/build.gradle' line: 10
* What went wrong:
A problem occurred evaluating project ':expo-application'.
>
Could not find method useDefaultAndroidSdkVersions() for arguments [] on project ':expo-application' of type org.gradle.api.Project.
* 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
==============================================================================
2: Task failed with an exception.
-----------
* Where:
Script '/home/expo/workingdir/build/node_modules/expo-modules-core/android/ExpoModulesCorePlugin.gradle' line: 65
* What went wrong:
A problem occurred configuring project ':expo'.
>
Could not get unknown property 'release' for SoftwareComponent container of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
* 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 1m 16s
5 actionable tasks: 5 executed
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

我已尝试重新安装节点模块并再次安装了 jdk 17

3个回答

确保

npm ls expo-modules-core

至少显示版本 [email protected] 。如果它显示旧版本,并且旁边紧跟着 overridden ,请从 package.json 中删除该覆盖。无论哪种方式,请在之后运行 npm upgrade ,然后重试。

您可以通过查看 node_modules/expo-modules-core/android/ExpoModulesCorePlugin.gradle 来确认您获取的版本是否正确。如果其中不包含 ext.useDefaultAndroidSdkVersions 的定义,则表示您的版本太旧,您将遇到本文中显示的错误。

Mitja
2024-06-21

我遇到了同样的问题。这个问题发生在我主电脑上,我使用两台不同的电脑来编码,其中一台开始出现此错误。

我尝试重新安装 android studio 和我的 sdk,更改模拟器并修复依赖项,但似乎没有任何效果。最奇怪的是,该项目在其他机器上运行良好。

Lucas Dias
2024-06-14

运行此命令即可修复:

npx expo install --fix
Dmitriy S
2024-07-09