34

I am trying to run my project on the android simulator. When I run react-native run-android I am getting the following:

FAILURE: Build failed with an exception.

* What went wrong: Task 'installDebug' not found in root project 'android'.

* Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

If I run ./gradlew tasks I get:

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'android'.
components - Displays the components produced by root project 'android'. [incubating]
dependencies - Displays all dependencies declared in root project 'android'.
dependencyInsight - Displays the insight into a specific dependency in root project 'android'.
help - Displays a help message.
model - Displays the configuration model of root project 'android'. [incubating]
projects - Displays the sub-projects of root project 'android'.
properties - Displays the properties of root project 'android'.
tasks - Displays the tasks runnable from root project 'android'.

Any idea why I don't have a installDebug task in my project? How do I get it back?

Stephen Horvath
  • 5,188
  • 3
  • 24
  • 31

22 Answers22

23

react-native run-android --variant [productFlavorName][debug/release]

e.g. react-native run-android --variant Huaweidebug

Kenny Tian
  • 347
  • 2
  • 5
  • 33
    You can improve the quality of your Answer by including an explanation of why they don't have an `installDebug` task in their project and how your suggested solution would solve their problem. – toonice May 12 '17 at 03:32
  • `Task 'installHuaweidebug' not found in project ':app'.` Same as earlier except `installHuaweidebug` changed to `installHuaweidebug' :) – Sami Jul 15 '23 at 07:12
16

For Debug test

react-native run-android --variant devKernelDebug

The reasons is because in the file android/build.gradle we have this

  productFlavors {
    devKernel {
      dimension 'remoteKernel'
    }
    prodKernel {
      dimension 'remoteKernel'
    }
  }
Marco
  • 191
  • 1
  • 3
8

i had the same issue in fresh react-native project (react-native init projectname) after running react-native start then react-native run-android in VS code. It gave this error

Task 'installDebug' not found in project ':app'.

It is in RN "0.62.1"

Solution:- i open Android Studio, then clean and rebuild.

I am not sure would it work after clean and rebuild.

i also did and gave the sdk path in root project

export ANDROID_HOME=/home/mycomputer/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Then it works.

My npm version 6.7.0 My Node version v11.10.1 react-native-cli: 2.0.1 react-native: 0.62.1

Raikumar Khangembam
  • 948
  • 1
  • 12
  • 24
  • Could you show where this "Clean and Rebuild" option is? I have the exact same error, but I can't find this option. Also, which document do you add the SDK Path to? – mrmicrowaveoven May 07 '21 at 17:04
  • Open Android Studio and open your project. I think it syncs the Gradle when it starts, after that, you will see Build in the above tab bar of android studio. there is a Clean project and a Rebuild project. For SDK path, I am using Ubuntu. When I installed the android studio package with SDK, after installing it creates the Android directory inside the Desktop direction, I get the path of SDK. Give the path in the terminal using the above code. I found it from one stackoverflow question for giving the path. – Raikumar Khangembam May 08 '21 at 05:59
7

I was also having this issue with one more issue

Deprecated Gradle were used in this build, making it incompatible with Gradle 7.0.

in Android build as the screenshot attached.

enter image description here

On opening the android folder with android studio and letting it build by android studio, the problem is getting fixed. After that on running

npx react-native run-android

, it is working fine.

Anand Kumar Jha
  • 614
  • 9
  • 23
7

I have solved this problem You just need to Create file in Android Folder

Go android folder

Create file local.properties

then just add this code in local.properties file:-

If you are using MacBook then sdk.dir=/Users/USERNAME/Library/android/sdk

if you are using Windows then sdk.dir=C:\Users\USERNAME\AppData\Local\Android\sdk

if you are using Linux then sdk.dir = /home/USERNAME/Android/sdk

if you want to know what is your system USERNAME then just use command for Mac whoami

and then just rerun command react-native run-android

Thanks :)

  • 1
    Thanks. For me that worked fine but somehow I had to add a double slash on my windows: `sdk.dir=C:\\Users\\USERNAME\\AppData\\Local\\Android\\Sdk`. Adding the `local.properties` file however as well as the `sdk.dir` parameter were definitely what I had to do. – vm2013 May 23 '20 at 16:17
  • I already have that line added, but the error keeps showing :( – iamalinski Apr 27 '22 at 13:04
4
cd android
./gradlew clean
cd..
react-native run-android --variant=DevDebug

This fixed for me

Rajesh N
  • 6,198
  • 2
  • 47
  • 58
  • 1
    Thank you! I did have a follow-up error when running `./gradlew clean`: `Failed to install the following Android SDK packages as some licences have not been accepted` https://stackoverflow.com/a/43003932/6168487 <-- this answer fixed that bug, then your solution fixed the rest. – mrmicrowaveoven May 07 '21 at 17:19
4

The error comes when the project is constructed on flavors.

Flavors is the solution when you need to build the same app but for different clients, like one for Facebook and one for Microsoft, and you have to do some minor adjustments to your code. More about flavors here: https://blog.logicwind.com/adding-multiple-target/

So, to solve this, for the Android system, go to android/app/build.gradle

Now find the next part:

android {

...

flavorDimensions "default"

productFlavors {
    dev {
        minSdkVersion rootProject.ext.minSdkVersion
        applicationId 'com.myproject.dev'
        targetSdkVersion rootProject.ext.targetSdkVersion
        resValue "string", "build_config_package", "com.myapp"
    }
    prod {
        minSdkVersion rootProject.ext.minSdkVersion
        applicationId 'com.myproject'
        targetSdkVersion rootProject.ext.targetSdkVersion
        resValue "string", "build_config_package", "com.myapp"
    }
    facebook {
        minSdkVersion rootProject.ext.minSdkVersion
        applicationId 'com.myproject.facebook'
        targetSdkVersion rootProject.ext.targetSdkVersion
        resValue "string", "build_config_package", "com.myapp"
    }
}

defaultConfig {
    applicationId "com.myproject"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}
...
}

As you can see in the productFlavors tag we have 3 different builds (dev, prod and facebook). Now, each of those flavors have two different runtime modes (or builds) (Debug and Release). So, as others suggested, when you build your app, you will have to specify the flavor you want to build.

The command you will need to use is next:

npx react-native run-android --variant <productFlavour><BuildType>

Looking up at the build.gradle, for this project we have the next possible variants:

devDebug and devRelease, prodDebug and prodRelease, facebookDebug and facebookRelease

Depending on your configuration, just adjust the productFlavor and you are good to go

2

Following steps worked for me:

Right click the "android" folder and click "Open in Integrated Terminal"

enter image description here

Run "gradlew tasks" command.

enter image description here

Scroll down to "Install tasks" section:

enter image description here

The list will contain the variants which you will pass against the run-android command. Taking for instance the "installExperimentalFossDebug" task, the variant will be "ExperimentalFossDebug".

Next step is to run the "run android" command at the root of the project (not in the android folder) with that variant.

npx react-native run-android  --variant ExperimentalFossDebug

enter image description here

Following the above steps you will be able to run the project against emulator: enter image description here

Raghav
  • 8,772
  • 6
  • 82
  • 106
1

just change this,go to this folder and file,

node_modules/react-native/local-cli/runAndroid/runAndroid.js

replace installdebug with

} else { gradleArgs.push('installDevDebug'); }

Harish_Madugula
  • 187
  • 1
  • 2
  • 8
1

Below command solved my issue:

Run--> gradlew :app:installDebug inside ./android folder

After installation run gradlew tasks to list down the tasks available. There you can check

Install tasks

installDebug - Installs the Debug build.

installDebugAndroidTest - Installs the android (on device) tests for the Debug build.

uninstallAll - Uninstall all applications.

uninstallDebug - Uninstalls the Debug build.

uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.

uninstallRelease - Uninstalls the Release build.

Niladri
  • 69
  • 1
  • 3
1

I know this is an old question, but just in case : had the same trouble today with a react-native project, juste double check that your ANDROID_HOME environment variable is set to your local SDK folder.

You may try "react-native doctor" to see what's happening; but it make sense : without ANDROID_HOME, react-native just doesn't know what to build, so you can't run anything.

WonsElom
  • 650
  • 5
  • 5
1

Open the project with android studio, it will automatically fix the issues

Roshan Nizar
  • 114
  • 1
  • 5
  • Why does this fix it? Trying to fix an issue related to a missing .so file only when compiled with Android Studio (not with ./gradlew installDebug) – Ryan Tremblay Aug 21 '20 at 03:53
  • 1
    The root of the project is included in the ./gradlew, sometimes you might be missing those files or incorrect root, so to fix these, simply opening the project through android studio will fix it. – Roshan Nizar Aug 30 '20 at 06:57
1

I had the same issue with react native. Finally able to solve the issue by following the exact environment set guideline in the rest-native documentation. Go through the documentation in the URL below. Good luck. enter link description here

Chamath Jeevan
  • 5,072
  • 1
  • 24
  • 27
1

The error comes when the project is constructed on flavors

i was writing npx react-native run-android -variant=devDebug which was causing an issue but as soon as i write npx react-native run-android --variant devDebug it is working fine for me. working on windows laptop

Syed Amir Ali
  • 873
  • 12
  • 22
0

I am pasting the code to show some of the available options for run-android

var _default = {
  name: 'run-android',
  description: 'builds your app and starts it on a connected Android emulator or device',
  func: runAndroid,
  options: [{
    name: '--root [string]',
    description: 'Override the root directory for the android build (which contains the android directory)',
    default: ''
  }, {
    name: '--variant [string]',
    description: "Specify your app's build variant",
    default: 'debug'
  }, {
    name: '--appFolder [string]',
    description: 'Specify a different application folder name for the android source. If not, we assume is "app"',
    default: 'app'
  }, {
    name: '--appId [string]',
    description: 'Specify an applicationId to launch after build.',
    default: ''
  }, {
    name: '--appIdSuffix [string]',
    description: 'Specify an applicationIdSuffix to launch after build.',
    default: ''
  }, {
    name: '--main-activity [string]',
    description: 'Name of the activity to start',
    default: 'MainActivity'
  }, {
    name: '--deviceId [string]',
    description: 'builds your app and starts it on a specific device/simulator with the ' + 'given device id (listed by running "adb devices" on the command line).'
  }, {
    name: '--no-packager',
    description: 'Do not launch packager while building'
  }, {
    name: '--port [number]',
    default: process.env.RCT_METRO_PORT || 8081,
    parse: val => Number(val)
  }, {
    name: '--terminal [string]',
    description: 'Launches the Metro Bundler in a new window using the specified terminal path.',
    default: (0, _cliTools().getDefaultUserTerminal)()
  }, {
    name: '--tasks [list]',
    description: 'Run custom Gradle tasks. By default it\'s "installDebug"',
    parse: val => val.split(',')
  }, {
    name: '--no-jetifier',
    description: 'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
    default: false
  }]
};

I hope the answer is helpful

Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97
0

The solution is simple-

  1. Open the react-native app's android folder in Android studio.
  2. Select the app folder and click on Menu -> Build -> Re-build.
  3. If it asks for updates or some recommended actions, accept them all.
  4. MOST IMPORTANT, modify the permission of the gradlew.bat file. To do so, open the react-native app in the terminal and run-
chmod +x android/gradlew.bat 

And then finally run-

npx react-native start
npx react-native run-android
Deepak Panwar
  • 160
  • 10
0

The following command solved the problem for me on Linux. You should replace ~/Android/Sdk with your own Android SDK path.

export ANDROID_SDK_ROOT=~/Android/Sdk
0

Open you React Native project's android folder in Android Studio, for me it automatically generated

local.properties

which contains the sdk.dir

Then go back to the root of your React Native project and run

yarn android
Kandarp
  • 893
  • 7
  • 8
0

I got the same error. I just opened the VS Code and inside the android folder, I created local.properties file and then added sdk.dir=/Users/apple/Library/Android/sdk(Don't copy mine you can find your sdk path in android studio). Later, I ran npx react-native run-android and this solved my problem.

Vivek S
  • 1
  • 1
0

You must run gradlew in the android directory.

Here’s an example. Run the following command and it will produce the same output the OP mentioned.

./android/gradlew tasks

Then try:

cd android
./gradlew tasks

The output is wildly different. I don't know why this is the case.

Jeff
  • 133
  • 1
  • 8
0

Open Android folder in the Android studio then it will download all required files automatically

Salman
  • 191
  • 9
-1

Remove productFlavors code from android/app/build.gradle

rahul
  • 27
  • 7