在 React Native Android 中未指定 compileSdkVersion 错误

sfl*_*low 5 android android-gradle-plugin react-native react-native-android

当我尝试在 React Native 项目中构建 Android 应用程序时出现构建错误。

当我运行时react-native run-android,它说:

> Configure project :react-native-os
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-os'.
> compileSdkVersion is not specified.
Run Code Online (Sandbox Code Playgroud)

在 Android Studio 中,我可以看到它说的是同样的话: Cause: compileSdkVersion is not specified.

所以我在 Android Studio 中编辑了 build.gradle(Module: app) 文件,但问题仍然存在,错误信息没有改变。

android {
//    compileSdkVersion rootProject.ext.compileSdkVersion
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
Run Code Online (Sandbox Code Playgroud)

我在其他线程中尝试过类似这样的解决方案,但没有任何效果。有谁知道这里的问题是什么?

Amr*_*man 7

我也遇到了同样的问题,解决方法是:

npm i @react-native-firebase/app1-在终端中运行

2-按照以下步骤将 firebase 添加到 android 平台。

  • 如果我们不使用 firebase,为什么还需要 firebase 库? (3认同)

小智 0

我认为您正在使用Android Supported Library

如果您是27+ 支持的库,您应该使用compileSdkVersion 27targetSdkVersion 27