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?
react-native run-android --variant [productFlavorName][debug/release]
e.g.
react-native run-android --variant Huaweidebug
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'
}
}
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
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.
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.
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 :)
cd android
./gradlew clean
cd..
react-native run-android --variant=DevDebug
This fixed for me
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
Following steps worked for me:
Right click the "android" folder and click "Open in Integrated Terminal"
Run "gradlew tasks" command.
Scroll down to "Install tasks" section:
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
Following the above steps you will be able to run the project against emulator:
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');
}
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.
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.
Open the project with android studio, it will automatically fix the issues
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
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
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
The solution is simple-
Open the react-native app's android folder in Android studio.
Select the app folder and click on Menu -> Build -> Re-build.
If it asks for updates or some recommended actions, accept them all.
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
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
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
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.
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.
Open Android folder in the Android studio then it will download all required files automatically
Remove productFlavors code from android/app/build.gradle
I'm just trying to adapt to Android Studio, and I'm not enjoying it much.
A cursory glance at the Gradle site suggests that an aim is to be able to make the same build from the command-line as the IDE. If so, presumably it's possible to use Gradle to build Android Studio projects wtihout running Android Studio.
How can I do this? Are there any online examples?
Building in Debug Mode
For immediate application testing and debugging, you can build your application in debug mode and immediately install it on an emulator. In debug mode, the build tools automatically sign your application with a debug key and optimize the package with zipalign.
On Windows platforms, type this command:
> gradlew.bat assembleDebug
On Mac OS and Linux platforms, type these commands:
$ chmod +x gradlew
$ ./gradlew assembleDebug
To see a list of all available build tasks for your project, type this command:
$ ./gradlew tasks
Building in Release Mode
Build signed and aligned
If you would like, you can configure the Android build script to automatically sign and align your application package. To do so, you must provide the path to your keystore and the name of your key alias in your modules's build.gradle file. With this information provided, the build will prompt you for your keystore and alias password when you build using the release build type and produce your final application package, which will be ready for distribution.
To specify your keystore and alias, open the module build.gradle file (found in the root of the module directory) and add entries for storeFile, storePassword, keyAlias and keyPassword. For example:
storeFile file("myreleasekey.keystore")
keyAlias "MyReleaseKey"
Save your changes. Now you can build a signed .apk in release mode:
Open a command-line and navigate to the root of your module directory.
Edit the build.gradle file to build your project in release mode:
...
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file("myreleasekey.keystore")
storePassword "password"
keyAlias "MyReleaseKey"
keyPassword "password"
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
Hope it helps
recently I updated my working android studio IDE into Android Studio 1.5.1. but now I'm facing some trouble as after updating it did not generating signed apk file. but when I plug a device and run the app, it runs properly. when I use
Build -> Generate Signed Apk
in the Event Log it shows
10:38:51 AM Executing tasks: [:app:assembleRelease]
and the slider shows some time and it disappear. It does not show build generation completion dialog too. then I change build variant and try to run the app using a connected device. and in the Event Log it sows
10:43:32 AM Executing tasks: [:app:assembleDebug]
after few seconds a pop up coms saying Apk(s) generated successfully, but still the signed apk is not there at the relavent folder. and the app runs in the device properly. and my full Event Log is as follow.
10:38:51 AM Executing tasks: [:app:assembleRelease]
10:43:32 AM Executing tasks: [:app:assembleDebug]
10:43:46 AM Gradle build finished in 13s 964ms
10:43:46 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:46 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:46 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:46 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:47 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:47 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:47 AM Generate Signed APK
APK(s) generated successfully.
Reveal in Finder
10:43:52 AM Session 'app': Launched on samsung-sm_t211-4100cede9628b000
also my build.gradel file is as following.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '23.0.0 rc3'
defaultConfig {
applicationId "com.lf"
minSdkVersion 14
targetSdkVersion 19
versionCode 63
versionName '2.0.9'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile project(':holoColorPickermaster')
compile project(':qRCodeReaderViewlib')
compile project(':volley')
compile project(':library')
}
so how can I fix this. I fully update Android studio after this was happen and it still the same.
I was facing same issue but i resolved the issue by adding below code in build.gradle
lintOptions {
checkReleaseBuilds false
}
This issue would occur, Sometimes our application not follow all the rules and regulation according to Lint Tool
Note: Add this in application module inside android
For Android Studio 3, instead of putting the APK directly into the folder, it creates a "release" folder or a folder that matches the flavor of your build.
So when you click locate, it puts you at the app level. You need to go into the release folder to get your APK file.
Typically you'd look in the release folder:
But if you built some other flavor aside from the release flavor, you would look for a folder with that name.
Ensure that your keystore is correct, with the correct passwords and
paths.
Then clean and rebuild.
Assemble (NOT EXECUTE OR RUN) the required build
Then 'Generate signed APK'
I fixed this issue by completely removing Android studio and it's related files and re install it. and now its working perfectly. it may be some issue with the plugins I'm using with the IDE. So in my mac I used following terminal commands to remove android studio
rm -Rf /Applications/Android\ Studio.app
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/com.google.android.studio.plist
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*
rm -Rf ~/Library/Caches/AndroidStudio*
rm -Rf ~/.gradle
rm -Rf ~/.android
then I re install the IDE and install necessary SDKs. this fixed issue for me.