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
I found the solution at this answer
by adding the code below to buildscripts section in build.gradle file:
}
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.
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
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.