Search code examples
androidreact-nativeadb

cannot run ADB: the operation requires elevation


I recently started learning React-Native and was trying to run a project on Android emulator.However, this was succeeded at the first attempt, but now It doesn't, throwing the following error.

Execution failed for task ':app:installDebug'.

java.io.IOException: Cannot run program "C:\Users\Pavindu\AppData\Local\Android\Sdk\platform-tools\adb.exe": CreateProcess error=740, The requested operation requires elevation

Since this is a well known error message,I could find lot of answers regarding this error.The following were the actions I took according to those answers.But none of those helped me.

  1. Running both android studio and cmd as administrator
  2. Running cmd /c react-native run-android
  3. Deleting node_modules and npm install

Solution

  • After struggling a lot, here is what I did to overcome the problem.

    • Copied /Sdk folder and pasted it in a different location while keeping the old SDK folder there.
    • Deleted platform-tools folder in copied SDK folder
    • downloaded platform-tools from android site and added it to new SDK folder.
    • set new SDK location to ANDROID_HOME (I use windows)

    and android/build.properties file in my react-native project.

    sdk.dir="C:\\path\\to\\new\\sdk"

    When I run react-native run-android after these steps,all started working fine.

    Note: I know that this seems hacky, but as a help for someone, I decided to write this .