skip to Main Content

I am trying to use react-native-selectable-text in my react native project. but when I build the project on android emulator it fails and this message appears

FAILURE: Build failed with an exception.

* What went wrong: Could not determine the dependencies of task ':react-native-selectable-text:bundleLibCompileToJarDebug'. > Could not create task ':react-native-selectable-text:compileDebugJavaWithJavac'. > In order to compile Java 9+ source, please set compileSdkVersion to 30 or above

Can any body tell me how can I solve this problem please?

I did the steps of adding package according to the instructions in documantation but as I using kotlin instead of java When adding RNSelectableTextPackage() to the list returned by getPackages function in MainActivity.kt I couldn’t find the getPackages function so I added this lines to the ‘MainActivity’ class

override fun getPackages(): List<ReactPackage> = PackageList(this).packages.apply { new RNSelectableTextPackage() }

I tried this by both "add" and "new", but none of them worked.

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution at this answer

    by adding the code below to buildscripts section in build.gradle file:

    subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
    

    }


    • The error message you’re seeing is because the react-native-selectable-text package requires a compileSdkVersion of 30 or above. This is because the package uses Java 9+ features, which are not supported by default in older versions of Android.

    • Open your android/app/build.gradle file & Update the compileSdkVersion to 30 or above.

      android {
        compileSdkVersion 30 // or a higher version
        defaultConfig {
            applicationId "com.yourprojectname"
            minSdkVersion 21
            targetSdkVersion 30
            versionCode 1
            versionName "1.0"
        }
        // ...
      }
      
    • Regarding the getPackages function, it seems like you’re using a Kotlin-based React Native project. In this case, you should add the RNSelectableTextPackage to the list of packages returned by the packages function in your MainActivity.kt

      override fun getPackages(): List<ReactPackage> {
        return PackageList(this).packages.apply {
            add(RNSelectableTextPackage())
        }
      }
      

    Note : If you’re using a newer version of React Native that uses autolinking, you may not need to manually add the package to the list of packages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search