在react-native-safe-area-context build.gradle文件中获取错误,并且未指定compileSdkVersion

yshpjwxd  于 2023-05-29  发布在  React
关注(0)|答案(1)|浏览(235)

我在构建react native项目时收到此错误消息。

BUILD FAILED in 4s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\sawan\OneDrive\Desktop\Unsplash\app\node_modules\react-native-safe-area-context\android\build.gradle' line: 28

* What went wrong:
A problem occurred evaluating project ':react-native-safe-area-context'.
> Could not initialize class org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':react-native-safe-area-context'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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.
==============================================================================

它说的错误是在这个文件:C:\Users\sawan\OneDrive\Desktop\Unsplash\app\node_modules\react-native-safe-area-context\android\build.gradle

//rest of the code ...
android {
compileSdkVersion getExtOrDefault('compileSdkVersion', 30)

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
    ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
    ndkVersion rootProject.ext.ndkVersion
}

defaultConfig {
    minSdkVersion getExtOrDefault('minSdkVersion', 16)
    targetSdkVersion getExtOrDefault('targetSdkVersion', 28)
    versionCode 1
    versionName "1.0"
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

    ndk {
         abiFilters (*reactNativeArchitectures())
     }
}// rest of the code ....

这是我的build.gradle文件,来自\android

buildscript {
ext {
    buildToolsVersion = "33.0.0"
    minSdkVersion = 21
    compileSdkVersion = 33
    targetSdkVersion = 33

    // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
    ndkVersion = "23.1.7779620"
    // kotlin_version = '1.5.20' //
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath("com.android.tools.build:gradle:7.3.1")
    classpath("com.facebook.react:react-native-gradle-plugin")
    // classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") //
}}

不知道错误是否在此路径或build.gradle文件中

g2ieeal7

g2ieeal71#

它与 “gradle cache” 有关。

只需清理gradle缓存,例如:

rm -rf ~/.gradle
然后;
yarn androidnpx react-native run-android
希望这个能帮上忙👍
引用自**me (@Pranav-yadav)**此处:https://github.com/th3rdwave/react-native-safe-area-context/issues/391#issuecomment-1565925679
P.S.:清理gradle缓存后,您将第一次构建,它将下载所需的gradle文件,因此,将消耗“更多”的带宽为第一次构建。之后它会像往常一样建造。:)

相关问题