Flutter codes not executing on android emulator - java

C:\Users\TomiwaPC>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Version 10.0.18362.30], locale en-NG)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Connected device (2 available)
• No issues found!
I have upgraded my flutter. Done everything I could
No error was reported.
Please I would like to know how i can resolve this issue.
Please find below the links to screenshots for some clarification:
[flutter and emulator screenshots][1]
[1]: https://i.stack.imgur.com/Sz0Aq.png
[android sdk screenshots][2]
[2]: https://i.stack.imgur.com/jS3og.png
[project structure screenshots][3]
[3]: https://i.stack.imgur.com/PU25L.png
I would be glad if you can assist with your experience.
Thanks in anticipation

Have you made sure that in the emulator is connected? I use android studio and there is a dropdown menu to select an emulator.
Here's what my one looks like, it's at the top toolbar section:

Run flutter devices and ensure your device is listed, then run flutter run in your project directory.

Did you run "flutter pub get" on the terminal for fetching dependencies before running the project?

Related

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" within flutter

the problem with android licenses
and when i tried fixing it the problem was in java
when I typed flutter doctor
[√] Flutter (Channel stable, 3.7.1, on Microsoft Windows [Version 10.0.22621.1105], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.6)
[√] Android Studio (version 2022.1)
[√] VS Code (version 1.75.0)
[√] Connected device (3 available)
[√] HTTP Host Availability
! Doctor found issues in 1 category.
and when I typed
flutter doctor --android-licenses
this error appears
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
so can someone help:face_with_monocle: note :the java and javac on my pc are the same version
run this command in the command prompt
flutter doctor --android-licenses
and type y and enter when you are asked.
and as you mentioned you are getting error here is the solution for your error that is given at another question https://stackoverflow.com/a/31523756/14466860 check out this

Unable to find bundled java version. flutter doctor

I'm facing this issue on windows after upgrading Android Studio to Electric Eel.
flutter doctor returns:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.22621.1105], locale en-US)
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3)
X The current Visual Studio installation is incomplete. Please reinstall Visual Studio.
[!] Android Studio (version 2022.1)
X Unable to find bundled Java version.
[√] VS Code (version 1.74.3)
[√] Connected device (4 available)
[√] HTTP Host Availability
! Doctor found issues in 2 categories.
I've tried adding a JAVA_HOME kind of solution but didn't work for me.
I had that problem today after updating Android Studio, and found an answer here:
https://github.com/flutter/flutter/issues/118502
The solution is basically:
Go to your AndroidStudio folder (normally C:\Program Files\Android\Android Studio in Windows)
Copy the content of jbr and paste the content into jre folder
Quick workaround from here: https://github.com/flutter/flutter/issues/118502#issuecomment-1384954269
Run in the terminal:
cd /Applications/Android\ Studio.app/Contents
ln -s jbr jre
*solution for MacOS

Flutter unable to locate Java Runtime after updating Android Studio?

I updated android studio to Electric El, but after updating, it is unable to find Java Runtime.
Flutter doctor gives this error and the code does not compile.
maazaftab#maazs-MacBook-Pro edge-focus-mobile % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
[✓] Flutter (Channel beta, 3.7.0-1.2.pre, on macOS 13.0.1 22A400 darwin-arm64, locale en-PK)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
✗ Could not determine java version
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2022.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
In your zshrc file add.
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home
Restart the android studio. Flutter doctor will give this.
maazaftab#maazs-MacBook-Pro edge-focus-mobile % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 3.7.0-1.2.pre, on macOS 13.0.1 22A400 darwin-arm64, locale en-PK)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2022.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
You can ignore the warning ✗ Unable to find bundled Java version. but the code will compile successfully.
Open the folder where Android Studio is installed.
In most cases, it is "C:\Program Files\Android\Android Studio"
Open the "jbr" folder inside the Android Studio folder ("C:\Program Files\Android\Android Studio\jbr"), and copy all contents in it.
Then go back and create a new folder called "jre" -> "C:\Program Files\Android\Android Studio\jre"
Paste all contents which you copied from "jbr" folder to "jre" folder.
Click Start and search for "Environment" and open "Edit the Environment variables" from search result.
Click to open "Environment variables"
On "User variables" pane click new and add new variable with name "JAVA_HOME" and path "C:\Program Files\Android\Android Studio\jre". Click OK to save.
Restart Android Studio and run flutter doctor. It will solve the problem.
Android Studio folder screenshot
Environment screenshot

Try re-installing or updating your Android SDK Manager

I am trying to install Flutter Enviroment and I found this error when I use this command:
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18362.720], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed
instructions.
[√] Android Studio (version 3.6)
[√] VS Code (version 1.43.1)
[!] Connected device
! No devices available
So When I use flutter doctor --android-licenses I found this error also:
A newer version of the Android SDK is required. To update, run:
C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update
When I tried to run this command C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update I found this error:
Error: Could not find or load main class '-XX:+IgnoreUnrecognizedVMOptions
Caused by: java.lang.ClassNotFoundException: '-XX:+IgnoreUnrecognizedVMOptions
So any one knows hoe to solve this problem
Go to the directory C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\
and then write the command:
sdkmanager --update
After that, run:
flutter doctor --android-licenses
You don't need to reinstall flutter.
You should just go to android studio->sdk manager-> sdk tools-> clear tick from Hide Obsolete Packages and tick Android Sdk tools (Obsolete) in order to install.
Finally it will be installed and you will able use flutter.
P.s. Don't forget to run to flutter doctor)
The Screenshot
Navigate in cmd to the needed folder. I think it was:
cd C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update
After this run the flutter doctor command.

Android license status unknown and a weird problem

Steps to Reproduce
I am running flutter in windows 10. I previously had a running android setup. After cloning the flutter repo and updating path, I ran flutter doctor -v. The logs are below. Now after searching a bit for solving the problem, I came across to this solution from various stackoverflow answers: Flutter.io Android License Status Unknown
I at first executed this:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
Though I don't know how to make it permanent. Then after running flutter doctor again, I came with another message, see log ###2
So it says Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4). So I ran flutter doctor --android-licenses accordingly. And it gives another error, that is:
A newer version of the Android SDK is required. To update, run:
C:\Users\imazi\AppData\Local\Android\sdk\tools\bin\sdkmanager --update
Well, so I ran C:\Users\imazi\AppData\Local\Android\sdk\tools\bin\sdkmanager --update to update it. And it kinda updated successfully outputting [=======================================] 100% Computing updates...
So I thought the issue is solved and ran flutter doctor again but it seems that nothing has been changed the problem still remains. It is like a loop. I do everything and the problem remains as it is. The output of the last flutter doctor is in log ### 3
My java version is:
10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
Please help.
!! also opened a github issue here: https://github.com/flutter/flutter/issues/39637
Logs
1 flutter doctor -v
O:\Flutter installation>flutter doctor -v
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
• Flutter version 1.7.8+hotfix.4 at O:\Work_Anon\Flutter installation\flutter
• Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
**• Android SDK at C:\Users\imazi\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.1
• Java binary at: O:\Work_Anon\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
**X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit
https://flutter.dev/setup/#android-setup for detailed instructions.****
[!] Android Studio (version 3.4)
• Android Studio at O:\Work_Anon\Android Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[!] Connected device
! No devices available
2 flutter doctor after set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
3 last flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1))
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
Actually, the problem got solved after installing jdk 8 and setting JAVA_HOME accordingly this new jdk. Also in the sdkmanager.bat file, located in C:\Users\username\AppData\Local\Android\Sdk\tools\bin
I added the line set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_221"
No need to uninstall java 10. That solved the whole problem!
Check if the flutter path is added.
Restart your system
Then run flutter doctor --android-licenses
accept all the licenses that appear
again run flutter doctor
and check if the issue persists
I uninstall the java jdk from my system and then let my flutter doctor arise that error of " [!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)"
and then followed the solution that flutter doctor was giving as it says to run the command " flutter doctor --android-licenses " and then type " y " as it says you to accept the licenses provided to solve this problem of "[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)" and then I again ran flutter doctor and the problem was resolved.

Categories

Resources