简体   繁体   中英

compileSdkVersion is not specified error in React Native Android

I get the build error when I try to build an Android app in my React Native project.

When I run react-native run-android , it says:

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

In Android Studio, I can see that it says the same thing: Cause: compileSdkVersion is not specified.

So I edited build.gradle(Module: app) file in Android Studio, but the problem persists and the error message doesn't change.

android {
//    compileSdkVersion rootProject.ext.compileSdkVersion
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

I tried solutions in other threads like this one but nothing worked. Does anyone know what the problem is here?

I also faced the same issue solved by :

1- run npm i @react-native-firebase/app

2- follow these steps to add firebase to the android platform.

Easiest and effective solution if this is happening with react native Move to node_module/@react-native-firebase/ for all modules example- app, firestore etc. Go to their android folder and open build.gradle you will see,

project.ext {
  set('react-native', [
    versions: [
      android : [
        minSdk    : 'same your project version root folder/android/app/build.gradle',
        targetSdk : 'same your project version root folder/android/app/build.gradle',
        compileSdk: 'same your project version root folder/android/app/build.gradle',           
        buildTools: 'same your project version root folder/android/app/build.gradle'
      ],

      firebase: [
        bom: firebaseBomVersion,
      ],
    ],
  ])
}

Hope this made it work. Happy Coding :)

Go to node_module>@react-native-firebase>messaging>android>build.gradle

Find code which defines min and target sdk and define the sdk and build version same as you have in your main project build.gradle file.

Then run command cd android &&./gradlew clean && cd..

Also make sure you had defined default firebase config in your app level build.gradle Make sure you have this import on top your build.gradle : apply plugin: "com.google.gms.google-services" and an default config as: defaultConfig { applicationId "..." minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 00 versionName "... multiDexEnabled true }

I think you are using Android Supported Library .

If you are 27+ Supported Library you should use compileSdkVersion 27 and targetSdkVersion 27

Make sure that you have in android/app/build.gradle:

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

(This error happened to me after I accidentally changed configurations.compile to configurations.implementation)

I also faced the same issue today and managed to resolve by :

  1. run npm i from project root directory
  2. sync the gradle, through opening the android folder inside Android Studio IDE (the sync process starts automatically, make sure the gradle sync is successful )
  3. $ cd android

    $ ./gradlew clean

    $ cd ..

    $ react-native run-android

Hope this helps

检查你的 android/app/build.gradle 是否有印刷错误。

My issue was caused by node command not found by gradle.

# fixed by linking the node path to the /usr/bin/node
# node is binary was located in $HOME/.nvm/versions/node/v14.13.0/bin/node
sudo ln -s $(which node) /usr/bin/node

When I run the above command the issue above disappeared.

Maybe I am too later to answer but the possible reason is if your build.gradle version is above 7 than you also may be getting the error of maven, Plugin with id 'maven' not found. If you try to follow the steps and solve that error that sdk compile error vanishes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM