Flutter not running on Android Device - android

I just created a new project using command palletes in vsCode. then i start android simulator and then flutter run. it's running perfectly on ios not on android .
this debug console response
Launching lib/main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugAidl'.
java.lang.IllegalStateException: aidl is missing from '/Users/sachin/Library/Android/sdk/build-tools/26.0.2/aidl'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Gradle build failed: 1
Exited (sigterm)

Just now I encounter the same problem. It happened because after doing "flutter run" there's still some file that needs to be downloaded, the build tools, but didn't get downloaded correctly, because I stopped it in the middle, since I thought the process was stuck.
So, these are the steps that solve the problem:
open terminal
change directory to /Users/[USERNAME]/Library/Android/sdk/build-tools/, in your case, type cd /Users/sachin/Library/Android/sdk/build-tools/
remove the folder that causes the error, in your case the 26.0.2 folder, so in your terminal type rm -r 26.0.2 to remove it.
go back to your code, make sure the android simulator is detected, and re run the project
now, wait patiently, it may takes sometime (depends on internet connection), but it's downloading the build tools, you can watch this in the finder by typing open .
make sure that in the 26.0.2 folder there's aidl file added when the process is finished.
it should be working, if not, just rebuild/re-run your code one more time. Done!

Related

flutter run returns error failed to create jar file

I'm trying to run 'flutter run' but it returns the following error. Any idea on whats causing this to happen?
Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling
software rendering with "--enable-software-rendering".
Launching lib\main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'android'.
Failed to create Jar file C:\Users\User.gradle\caches\jars-8\54252edd90659a19228cc919a3e977c6\kotlin-compiler-embeddable-1.3.50.jar.
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 5s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 6.3s
Exception: Gradle task assembleDebug failed with exit code 1
In my case, I freshly installed Flutter to my machine. I have created a new project, tried the compile it. In this first compilation process, it was taking long, so I have killed the compilation process with CTRL+C so that I can pass --verbose flag to flutter run to see what's taking so long. Then I got this error on the next verbose compilation.
Looking at the logs, I've managed to figure out that "Maybe, I have terminated the first compilation process while it was installing Gradle to my local machine, so it kinda screwed it up while it was doing its job.".
I have removed my ~/.gradle directory and rerun again and it worked flawlessly.
The problem here is, this folder
C:\Users\User.gradle\caches\jars-8\54252edd90659a19228cc919a3e977c6
Is currently empty. It should have kotlin-compiler-embeddable-1.3.50.jar. How I fixed this problem, I have searched on Google for kotlin-compiler-embeddable-1.3.50.jar. From Google, I have downloaded this kotlin-compiler-embeddable-1.3.50.jar. After downloading I have pasted that particular jar file here -> C:\Users\User.gradle\caches\jars-8\54252edd90659a19228cc919a3e977c6.
Now I am not getting this error anymore.
You can download kotlin-compiler-embeddable-1.3.50.jar from here :
https://jar-download.com/artifacts/org.jetbrains.kotlin/kotlin-compiler-client-embeddable/1.3.50/source-code

app:compileDebugJavaWithJavac'. > Could not find tools.jar Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`

when I use this command in the terminal:
PS C:\web dev\practice-projects\react-native\myproject> react-native run-android --no-jetifier
I get this whole error:
info JS server already running.
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error
Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
> Task :app:compileDebugJavaWithJavac 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_warning
14 actionable tasks: 2 executed, 12 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_271 contains a valid JDK installation.
* 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 39s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
My emulator isn't being launched and I have tried multiple fixes. I am getting started in react-native and don't understand the warnings or answers on similar questions. Please help.
There are few ways you can run your app,
Always works - Open the app from android studio. Select Open existing project and select android folder in your app to open the project and run from there after indexing is done.
Not sure would work and not recommended (might need release build) but you can drag your apk file that is auto generated to your simulator to install.
Add this line to gradle.properties file i.e. android/gradle.properties.
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home. replace the jdk version name or directory if required.
Note for mac - this is not library folder within your user directory so search them in your main drive location - should be something like machintosh hd
For windows - just replace the path after org.gradle.java.home=. Should be something like C:\\Program Files\\Java\\jdk1.8.0_144
In my case it was because the JAVA_HOME path could not find it.
Close all terminals and open a new one
Find a directory like this on your Mac:
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
What may change is the version, but once you have it, it runs in that
path:
export JAVA_HOME = / Library / Java / JavaVirtualMachines /
jdk1.8.0_91.jdk / Contents / Home
IN MY CASE I RUN THIS COMMAND AT THE ROOT OF THE REACT NATIVE PROJECT:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
AND IT WORKED.

Task 'installDebug' not found in project ':app'.in only one react-native project

I am new to React and first tried to do a Hello World Project. I got the mentioned error but also the error, that my sdk path is not set. So I configured a ANDROID_SDK_ROOT variable. Then it worked properly.
Now I want to run the rocket chat app from github on my android device. This is the project: https://github.com/RocketChat.
After navigating into the project (root), I first started the server with npm start, showing me a successful message. Then I wanted to run it on my phone, using npx react-native run-android.
This is the output I get:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
* 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. Run with --scan to get full
insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 5s
error Failed to install the app. Make sure you have the Android development environment set up:
https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
I know there are already some posts about this error and I tried their solutions so far, but without success yet.
My device is registered and is showing when I do adb devices. The global android sdk variable is also set.
What could have gone wrong? Can someone tell me what I am missing?
Thanks for every help!
I fixed it. None of the solutions worked but I found another way.
First, dont forget to start the server. Navigate to the root folder of your project and run npm start. This should run successfully. If it says your ports are already used, just open your task manager and terminate all tasks from NodeJS.
In your android folder, run the command gradlew tasks. This will show you a list of available commands. I dont know why, but the command installDebug was not there, hence the error.
But there were other tasks which sounded similar, for example installFossDebug.
So I ran npx react-native run-android --variant=installFossDebug. But it didnt work. The console showed me a new error, saying Task installInstallFossDebug could not be found (No Typo).
I dont know why install was twice in the task, so I just ran npx react-native run-android --variant=FossDebug and voila, it worked. The app started successfully on my android device.
Good luck! :-)

building flutter demo app failure with andriod emulator

device : Macbook pro catalina and all softwares are up to date .
I did all the correct steps for setting up flutter in android studio , installing the recommended emulator , every thing is ok but building flutter demo app didnt work in emulator (it was worked perfectly in IOS simulator) and showed this error :
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:desugarDebugFileDependencies'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
/Users/heshamayman/Library/Android/sdk/build-tools/28.0.3/core-lambda-stubs.jar
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 39s
Finished with error: Gradle task assembleDebug failed with exit code 1
The error you are facing might be due to partial installation of SDK on your device.
Here, how you may be able to fix it.
First Navigate to /Users/heshamayman/Library/Android/sdk/build-tools/ using finder.(CAN BE HIDDEN IN CASE PRESS [command+shift+.] TO SHOW HIDDEN FILE IN FINDER)
Then delete the folder 28.0.3
After DELETING:
In Android Studio:
GO TO TOOLS -> SDK MANAGER
SELECT SDK Tools -> Show Package Details -> select 28.0.3 (assuming it got deleted on first place).
This worked for me. Hope this will work for you also. :D

Failed to launch emulator. Reason: Emulator exited before boot en React Native when react-native run-android

I am installing React Native according to this website https://medium.com/#leonardobrunolima/react-native-tips-setting-up-your-development-environment-for-windows-d326635604ea, it's very useful until I run the command react-native run-android, this is the error I receive:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Launching emulator...
error Failed to launch emulator. Reason: Emulator exited before boot..
> Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
24 actionable tasks: 4 executed, 20 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> Could not read path 'C:\JesusApp\android\app\build\intermediates\transforms\mergeJniLibs\debug\0\lib\x86_64'.
* 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 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> Could not read path 'C:\JesusApp\android\app\build\intermediates\transforms\mergeJniLibs\debug\0\lib\x86_64'.
* 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 7s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (C:\JesusApp\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
My node version is 10, and I am working on Windows, please help, thank you.
I succeeded by doing the following steps:
Open android studio > AVD Manager > Actions (click the bottom icon) > Select Cool Boot Now.
Check your config and environment setup with instructions here, be very careful with pathes set up. Check the $PATH from your IDE's terminal.
check in the AVD that a particular Android OS is selected and installed for a virtual device you use (in my case it was not, I had yellow warning exclaim sign in an "Actions" column in an AVD's devices list).
Have your Gradle updated to at least 6.6 in the
android/gradle/wrapper/gradle-wrapper.properties
On Ubuntu after run I had to "push" switch-on button on the virtual device.
Finally, I got it up and running both on Windows 10 and Ubuntu 20.04 LTS with Android 30.
This might be the insufficient space in your machine or AVD or the mismatch in the configurations.
So, do the following steps to resolve this issue.
Verify that the environment variables are set for SDK path and adb.
Clean the project by Build -> Clean Project
Clean AVD by Open android studio > AVD Manager > Actions (click the bottom icon) > Select Cool Boot Now.
First start the android emulator on Android Studio, then execute the react-native run-android. If it doesn´t work go to android studio and do "Build -> Clean Project"
For me running
adb kill-server
and
adb start-server
worked
I also runned killall 9 node before that but it was not enough. MacOS asks for saving last state before restart also Android emulator asks before quiting it. Maybe the problem happens because saving a bad state and trying to start from that bad state. Not sure but I suspect one of these.
In my case, I've to wipe data on the virtual device.
Android Studio -> AVD -> Actions (↓) -> Wipe Data
I faced similar problem when executing my react-native code on Android Physical device. I am not sure if my solution will help.
We all know that ADB requires authorization from an Android device in order to communicate with it. It’s only by allowing the USB debugging and validating the computer’s RSA key fingerprint that we let the ADB daemon connect to our phone and control it. This is a security feature.
My phone was connected with USB and on changing USB Configuration on device, my phone gave me another prompt "Allow USB debugging?" Image available for reference. I got solution on reallow USB debugging
I had the same problem, only check the developer options and enable the debug by usb, on the device
For me, the problem ended up being quite simple. Working in react-native, I was running the following command from the terminal 'npx react-native run-android' in VS CODE. Though the emulator would run fine when started from Android Studios, I received the above error when running from the terminal in VS Code.
Solution: Run VS Code as Administrator. (or your terminal in general)
worked for me - there is not enough space on disk, Check that there is enough space on disk(where is the emulator was installed).
In my case, cool boot and wipe data didn't work. I just uninstall the virtual device and reinstall it and then it works for me.
Worked for me - reload system or clean system/android cache ./android/avd
Deleting the file app\build\intermediates\signing_config\debug\out\signing-config.json worked for me.

Categories

Resources