Issue in setting up the Android emulator with React native - android-emulator

I am fairly new to React native and trying to set up Android environment with Visual studio. All the installation has been fairly successful, however, when I try to run the sample app on the android emulator executing the npx react-native run-android command it shows below error -
'C:\Users\Home' is not recognized as an internal or external command,
operable program or batch file.
error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:109)
However, when i execute adb devices on visual studio, it shows the list of emulator connected -
List of devices attached
emulator-5554 device
What could be the possible reason? Is this because my users name is Home PC? (Is this because there is a space in between) and it is not able to get the correct path?

This is because your java version is updated to the latest version and gradle is not supported with the installed version. what you can do is update the gradle as well
So go to gradle/wrapper folder inside the android folder
Edit gradle-wrapper.properties file and replace distributionUrl
with following value
https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

I too faced the same issue.The problem is with the JDK. From JDK 14 i downgraded to JDK 11(LTS) version. And it worked.
Hope it helps.

Install Java 8 version, which is available Java 8 download
Gradle is not keeping up with the Java Latest versions, so roll back
to previous versions

Related

Can't run flutter project due to error VERBOSE.dart error, isolate error

When I try to run my flutter-project code on the iOS simulator in VS code, I get the following error on the console:
Launching lib/main.dart on iPhone 11 Pro in debug mode...
lib/main.dart:1
Xcode build done. 24.4s
[VERBOSE-2:shell.cc(103)] Dart Error: Can't load Kernel binary: Invalid SDK hash.
[VERBOSE-2:dart_isolate.cc(171)] Could not prepare isolate.
[VERBOSE-2:runtime_controller.cc(415)] Could not create root isolate.
[VERBOSE-2:shell.cc(588)] Could not launch engine with configuration.
Thanks in advance.
Hi!
In my case, the error was caused by the forced shutdown of the IDE.
After manually selecting the libraries, I identified the one that was causing the problem, updated the project without it, and updated the project again with it.
With that the problem was solved.
Hope I have helped, if yes, please flag.
Could you delete the bin/cache folder, then run app
Open terminal and run: $ flutter channel beta
"it will install beta version, once installation is done, try it!"
"In case you willing to change the beta version to stable version you can use the following:"
$ flutter channel stable

Could not open settings generic class cache for settings file '

I reinstalled my android studio since the sdk was not found and so on. After re installing java jdk and android studio , everything worked well until I got an error saying 'Could not initialize class org.codehaus.groovy.runtime.InvokerHelper' which I solved by changing the Gradle version. And now the error is 'Type 'FlutterTask' property 'assets' is missing an input or output annotation.'
FAILURE: Build failed with an exception.
What went wrong:
Could not open settings generic class cache for settings file 'C:\Users\loran\ASProjects\xylophone-flutter\android\settings.gradle' (C:\Users\loran.gradle\caches\6.8.2\scripts\4mawlyb2l5e9tefyvnpxva1kg).
BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 60
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 46s
Exception: Gradle task assembleDebug failed with exit code 1
I also had this problem So I did install java 8
You might have Java 13 So install Java 8
Java JDK 16 is the one that seems to lead to this issue try downgrading by downloading a lower version of JDK preferable JDK 8 or 11
To future individuals who will run to this error. Here is the link to download the JDK enjoy your coding experience don't forget to change the path too.
https://www.oracle.com/java/technologies/javase-downloads.html
mainly you have jdk16 i tried to install java 8 and set env to java 8 it worked for me
Try installing the latest Gradle package gradle-7.1.1, if you are using Java JDK 16 installed. To do this open android/gradle/wrapper/gradle-wrapper.properties file and under distribution url, update the gradle version to 7.1.1 (or the latest). After that, inside your Flutter project directory, run the following command in the terminal:
cd android && ./gradlew
I removed the JAVA_HOME path to the JAVA download and changed JAVA_HOME path to the following:
C:\Program Files\Android\Android Studio\jre
I am now coding
FOUND IT !
No need to change your JDK version, follow the steps to resolve the issue:
check your java version and remember it, use "java -version" in terminal
go to your android studio path installation
then in: Android Studio/jre/ open the file named "release"
take attention of the value of JAVA_VERSION field
if it's not the same as the java version on your computer, just change it with the version installed on your computer.
That's it, i hope it will resolve your issue like it resolves mine.
Try it and give a feedback.
Try this!
Remove package android from the top of settings.gradle. This helped me out.
If this error occurs, this might because you have installed the latest JDK such as JDK 16. You download and install JDK 8 and uninstall JDK 16. Then restart the desktop/laptop and try launch and run flutter run again. It should be working fine.
In my case, on Windows 10, my JAVA_HOME was set to JAVA SE 16 C:\Program Files\Java\jdk-16 and when I looked at the release file in java jre in android studio, C:\Program Files\Android\Android Studio\jre\release, I found that the the JAVA_VERSION WAS "11.0.10" (java 11) for short. So I changed the java installation on my PC to Java 11, update JAVA_HOME in my environment variables to point to the new java (C:\Program Files\Java\jdk-11.0.12) and restarted android studio, Then everything worked.
You can get your java 11 from here.
https://www.oracle.com/java/technologies/javase-jdk11-downloads.html. Change 11 to 8, 16 etc to get the download link for the java version you need.
The problem has to do with having Java 13 or 16 installed on your computer. The current version of Flutter does not work with Java 13 and 16. Just uninstall either of these that you may have installed and installed Java 8 or Java 11. Restart your computer to effect the update. Everything should be fine afterwards
I got this error when using flutter. I fixed it ensuring the android-studio-dir path was set correctly.
You set it up using flutter config --android-studio-dir="android studio path".
Then run flutter doctor and ensure flutter can see Android Studio
In 'adnroid/gradle/wrapper/gradle-wrapper.properties'
Change distributionUrl to version 7.0.1
In 'android/build.gradle'
Change 'com.android.tools.build:gradle' to version 4.2.0
Java 11 is the only supported version by Flutter as for now. It compiles and installs.
Previously I had this error using Java 19 and Java 8.
You might want update your gradle version.
Check the supported gradle <-> kotlin <-> java version on their page.
You can try this, it works for me.
Open the android module to a new window and automatically download all necessary libraries after successfully building finished run the app.
Simply go to your Android Studio path -> C:\Program Files\Android\Android Studio
open jbr folder -> copy all files -> then go back -> paste all the files in the jre folder and "replace the files in the destination".
It works for me in two different laptops. I have latest jdk version - 19.0.2
The error message you're seeing is related to the flutter build process and it occurs when a required input or output annotation is missing from the assets property of the FlutterTask.
task buildFlutter(type: FlutterTask) {
// Add the #Input annotation to the assets property
#Input List<String> assets = ["assets/images/", "assets/fonts/"]
}
Try to disable AVAST, check system vatiables path for JDK and SDK, clear cache with yarn.

Ionic 2: error while running on Android platform

I'm using Ionic 2 when I used the command ionic cordova run android I had this error:
Fetching plugin "mx.ferreyra.callnumber#~0.0.2" via npm
ERROR running one or more of the platforms: Android SDK not found.
Make sure that it is installed. If it is not at the default location,
set the ANDROID_HOME environment variable.
You may not have the required environment or OS to run this project.
Can anyone tell me the solution?
Make sure that you have Android Studio installed. If it is, then set the environment variable mentioned in the error to the directory of where your SDK is,
on Windows %AppData%/Local/Android/SDK

Run react-native on android emulator

I try to run react-native app on genymotion android emulator on my mac.
When I write react-native run-android It gets
Running /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
error: closed
Could not run adb reverse: Command failed: /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
MacBook-Pro-MacBook:ART-CarefulPeople macbook$
Then I've tried:
react-native start
react-native run-android
The same result.
Then I've tried:
react-native bundle --entry-file index.android.js --platform android --bundle-output android/app/src/main/assets/index.android.bundle
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
react-native run-android
The same result.
I've tried just adb reverse tcp:8081 tcp:8081 and it says error: closed
When I try to run app on android-sdk emulator it gets the same error above but without error: closed.
From android studio I can run this app and it works on genymotion.
Tell me please what should I do to run my app on android emulator?
I had a similar problem, and after spending so much time and lots of searching about this issue the only trick worked for me:
Please Install the Required SDKs as shown in this figure
Configure Required SDKs
If You have already installed it, so you must have to update the following SDKs:
Android SDK Tool (update it to latest version)
Android SDK Platform-tools (update it to latest version)
Android SDK Build-tools (update it to latest version)
Android Support Repository under Extra folder (update it to latest version)
You Must have at least Installed the Same version Android API as the installed Android SDK Build-tools & Android SDK Platform-tools version as shown in the Configure Required SDKs figure above.
Note: Local Maven repository for Support Libraries which is listed as the SDK requirement in the official docs of React-native is now named as Android Support Repository in the SDK Manager .
On macOs I manage to fix this by adding:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
to ~/.zsh_profile file.
and than type to your terminal
source $HOME/.zsh_profile
The issue was caused by using iTerm2 shell so it's required to edit its own config instead of default $HOME/.bash_profile as described in the official documentation https://reactnative.dev/docs/environment-setup
React Native (On Mac OS Big SUR)
i was stuck here. But updating the environment settings for Android studio did the trick.
nano ~/.zshrc
and paste
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools:$PATH
export JAVA_HOME=$(/usr/libexec/java_home)
control + o to save
then enter
then control + x to exit
then do
source ~/.zshrc to compile
kill the runnig terminals and run
npx react-native run-android
You can also try use "doctor" command. It will fix most cases.
npx #react-native-community/cli doctor
I had similar issue running emulator from android studio everytime, or on a physical device. Instead, you can quickly run android emulator from command line,
android avd
Once the emulator is running, you can check with adb devices if the emulator shows up.
Then you can simply use
react-native run-android to run the app on the emulator.
Make sure you've platform tools installed to be able to use adb. Or you can use
brew install android-platform-tools
It happened to me that I had an instance of the packager running with an old project (I ran react-native start as usual). I was using Ubuntu 14.04. So what I did was to stop that instance and go to my project folder and in two different console tabs I ran these two commands separately:
npm start #here I used to run react-native start
react-native run-android
npm start is defined in my package.json as:
"start": "node_modules/react-native/packager/packager.sh"
I don't know if there is a sort of confusing stuff for react-native but that did the trick.
On Windows 10 and Android Studio you can go in Android Studio to "File"->"Settings" in Settings then to "Appearance & Behavior" -> "System Settings" -> "Android SDK".
In the Tab "SDK Tools" active:
"Android SDK Build-Tools .."
"Android Emulator"
"Android SDK Plattform-Tools"
"Android SDK Tools"
If all installed then you can start the Emulator in Android Studio with "Tools" -> "Android" -> "AVD Manager".
If the Emulator run you can try "react-native run-android"
If emulator not installed then try this command, (if homebrew installed)
brew install android-platform-tools
might be it will help.
Had a similar problem. I updated my Genymotion and my android SDK's/libraries/dependencies and all seemed to work. To update my SDK's I used android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk
In my case, there was an issue with the android/gradlew file. I think this happens when we move the code from Windows to Mac OS.
Reference:- https://stackoverflow.com/a/62216646/4786087
I was able to clean the android/gradlew file by running the following commands -
Step 1. On android folder cmd run
chmod +x gradlew
Step 2. After that run
./gradlew clean
Step 3. Next in the root of the project, run
react-native run-android
This should start building the app and launch it in the simulator if everything else is fine.
Try
brew cask install android-platform-tools
adb reverse tcp:9090 tcp:9090
run the app
In my case, this was happening because the android/gradlew file did not have execute permission. Once granted, this worked fine
You probably haven't run the Android SDK in forever.
So you probably just have to update it.
If you open the Android Studio Software it'll probably let you know that and ask to update it for you. Otherwise refer to following link: Update Android SDK

Android SDK: How to set up old versions? eg. gingerbread

my goal here is to run an android emulator with various old versions of Android to test web apps. I am an android newbie. I have a Nexus 7 with Jellybean. The bugs on the web apps are reported in older versions.
So far I have;
Installed Android SDK on a Windows 8 desktop, created and run emulators but it's limited to Android 4.2 only (Jellybean)
I think the next step is to run the SDK Manager -- Ecplipse > Window > Android SDK Manager
Doing this reports that the Manager will show shortly -- nothing happens. In the console I get this error;
[2013-02-09 16:31:49 - SDK Manager] [SDK Manager] \adt-bundle-windows-x86_64\sdk\tools\lib\\find_java.exe was unexpected at this time.
Running find_java.exe from the command line gives:
D:\Program Files (x86)\adt-bundle-windows-x86_64>sdk\tools\lib\\find_java.exe
C:\Program Files\Java\jre7\bin\java.exe
D:\Program Files (x86)\adt-bundle-windows-x86_64>where java
C:\Program Files\Java\jre7\bin\java.exe
C:\Windows\System32\java.exe
I have updated the PATH environment var to include the jre7 directory as above, and added a ANDROID_SDK_HOME as D:\Users\myuser_000\Documents\Workspace -- devices I create appear in a .android\avd sub-directory.
I am running the SDK on Windows 8, installed in D:\Program Files (x86)\adt-bundle-windows-x86_64
Is running the SDK Manager the correct action?
Any ideas what would cause the SDK Manager not to display?
Thank you!
The error was in the android.bat file.
I edited the following to comment out the call to find_java.bat and hard coded to my installed version of Java.
rem Check we have a valid Java.exe in the path.
set java_exe="C:\Program Files\Java\jre7\bin\java"
rem call lib\find_java.bat
Hope this helps someone in the future.
Something that may have complicated the issue was windows 8 catching android.bat as an unsafe program and automatically stopping it. I saw this when manually trying to run the batch file.