9

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

John Conde
  • 217,595
  • 99
  • 455
  • 496
Martin
  • 91
  • 1
  • 1
  • 3
  • Im trying to run my react app on Android Emulator but I got these Errors, I worked my app in ios simulator and all goes correctly BUT when i try to run on Android Emulator i get these errors. May somebody help me here, please?? Thank you by the way. – Martin Mar 31 '21 at 15:17
  • i just downgraded my unimodules from v 1.13 to 1.12 to fit my build tools and it worked ! try this – Hassan Kandil Apr 06 '21 at 12:01
  • 6
    In `android/build.gradle`, I changed the value of `compileSdkVersion` and `targetSdkVersion` from `29` to `30`. Then, the above error disappeared and worked. – byron1st Apr 19 '21 at 06:32
  • That fixed it for me @byron1st, thanks! – bkbooth Jun 01 '21 at 05:57

6 Answers6

14

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.

Nate
  • 516
  • 1
  • 5
  • 14
3

A new issue is reported in older RN version. Here's the issue and resolution: https://github.com/facebook/react-native/issues/35210

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33116267) – Thomas Smyth - Treliant Nov 11 '22 at 13:17
0

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")
Say u
  • 129
  • 11
0

If you created a project using 'npx', delete 'expo' dependencies from package.json. It works for me.

ouflak
  • 2,458
  • 10
  • 44
  • 49
0

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.

ANTARES_SEO
  • 317
  • 4
  • 9
0

You can have some error in your android/ios folder setup, remove folder and type expo-prebuild in your console. It generates new android and ios folders with proper settings. I had a lot of problems like that after upgrading my expo sdk.

Adam G
  • 11
  • 1