'ERROR ----> Task :expo-permissions:compileDebugKotlin FAILED
The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal. Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line. See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl The Kotlin plugin was loaded in the following projects: ':expo-av', ':react-native-agora'
Task :expo-permissions:compileDebugKotlin FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
175 actionable tasks: 2 executed, 173 up-to-date
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (12, 50): Unresolved reference: R
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (19, 52): Unresolved reference: R
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (40, 36): Unresolved reference: R
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':expo-permissions:compileDebugKotlin'.
Compilation error. See log for more details
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.
Get more help at https://help.gradle.org
BUILD FAILED in 17s
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 app:installDebug -PreactNativeDevServerPort=8081
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (12, 50): Unresolved reference: R
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (19, 52): Unresolved reference: R
e: /Users/development/Projects/myapp/node_modules/react-native-unimodules/node_modules/expo-permissions/android/src/main/java/expo/modules/permissions/requesters/BackgroundLocationRequester.kt: (40, 36): Unresolved reference: R
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':expo-permissions:compileDebugKotlin'.
Compilation error. See log for more details
Solution 1:[1]
My thoughts are this is a versioning issue. I solved this by changing the versions of buildTools, compileSdk and targetSdk.
Go to your android/build.gradle file and change the following values:
buildToolsVersion = "29.0.3" to buildToolsVersion = "30.0.0"
compileSdkVersion = 29 to compileSdkVersion = 30
targetSdkVersion = 29 to targetSdkVersion = 30
This sure saved me hours of stress. Let me know if it worked for you.
Edit:
I'm editing this answer to make it future proof, hopefully. Whenever this error occurs, check that the buildToolsVersion, compileSdkVersion and targetSdkVersion are using the latest the versions.
This also means you need to make sure your Android SDK, gradle or Android Studio is up-to-date.
Note: If you created your react-native project using the npx command and on the latest Android Studio, you might not need to specify the buildToolsVersion. For instance, at the time of editing this answer, buildToolsVersion is on 30.0.2 and my project is using 30.0.0. During build, Android Studio ignored my set version and used the latest.
Solution 2:[2]
I had a very similar issue. My solution was to go to open the file ./android/app/gradle/gradle-wrapper.properties i then changed distributionUrl to
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
also changed ./android/build.gradle
dependencies {
classpath("com.android.tools.build:gradle:4.2.0")
Solution 3:[3]
If you created a project using 'npx', delete 'expo' dependencies from package.json. It works for me.
Solution 4:[4]
I got slightly different error message, which was
What went wrong: Execution failed for task ':expo-permissions:compileDebugKotlin'.
After matching /android/build.gradle's kotlinVersion to android studio's kotlin version it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Say u |
| Solution 3 | ouflak |
| Solution 4 | ANTARES_SEO |
