31

I couldn't run the flutter app on android emulator or android phone. I installed the recently released android studio for arm-mac platform on m1 mac. Please answer if I am doing anything wrong here or is it the problem with the release itself.

Debug console output:

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Exception: Gradle task assembleDebug failed with exit code 1

flutter doctor -v output :

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 stable, 2.2.1, on macOS 11.4 20F71 darwin-arm, locale en-IN)
    • Flutter version 2.2.1 at /Users/hmnth/FlutterDev/flutter
    • Framework revision 02c026b03c (10 weeks ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/hmnth/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /usr/bin/java
    ✗ Could not determine java version

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio
    • Android Studio at Applications/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Android Studio not found at Applications/Contents
    • Try updating or re-installing Android Studio.

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.107

! Doctor found issues in 3 categories.
Yashwanth Ravula
  • 533
  • 1
  • 4
  • 17
  • you are using windows? if yes then install jaba and add its bin folder in envoirment variable – Akash Pal Aug 02 '21 at 11:57
  • Error is clear, do you have Java installed on your machine and set environment variables correctly? – Pradeep Simha Aug 02 '21 at 12:02
  • You need to install `Java`, here's how to install `Java` with `homebrew`: https://stackoverflow.com/questions/65601196/how-to-brew-install-java/70786302#70786302 – Cornelius Roemer Aug 12 '22 at 19:54
  • After updating my Android Studio .I am facing this issues . I resolved it using o to Applications -> right click on Android Studio -> choose "Show Package Contents". I have only folder .jbr (not have .jre). So, I create new folder with name .jre and copy folder "Contents" (from .jbr) -> paste to .jre folder. – Rahul Kushwaha Mar 23 '23 at 04:43

5 Answers5

37

Go to Applications then right click on Android Studio, then choose "Show Package Contents", create a new folder inside jre named jdk and copy the contents of jre to jdk

This is the link for the fix https://github.com/flutter/flutter/issues/76215#issuecomment-864407892

shim
  • 9,289
  • 12
  • 69
  • 108
Medo Elkamaly
  • 2,508
  • 1
  • 20
  • 15
  • 6
    Be sure to copy, not move. – Promlert Lovichit Dec 15 '21 at 13:31
  • 1
    you may also link : `cd jre` `mkdir jdk` `cd jdk` `ln -sf ../Contents Contents` – Serge B. Apr 29 '22 at 09:34
  • 3
    This did not work for me – vin shaba Aug 29 '22 at 23:20
  • Thanks, works for me, but I have "jbr" folder - "/Applications/Android Studio Preview.app/Contents/jbr" so I create new one - "/Applications/Android Studio Preview.app/Contents/jre" and create "jdk" inside this new folder and copy content and restart, it's work for me, does any one please let me know what is "jbr"? – Mayur Devmurari Feb 03 '23 at 08:55
  • After updating my Android Studio .I am facing this issues . I resolved it using o to Applications -> right click on Android Studio -> choose "Show Package Contents". I have only folder .jbr (not have .jre). So, I create new folder with name .jre and copy folder "Contents" (from .jbr) to .jre folder. not move . – Rahul Kushwaha Mar 23 '23 at 04:44
  • I don't have `jre` folder inside Contents – Balaji Jun 01 '23 at 08:53
16

In 2023.

Go to Applications -> right click on Android Studio -> choose "Show Package Contents".

I have only folder .jbr (not have .jre). So, I create new folder with name .jre and copy folder "Contents" (from .jbr) -> paste to .jre folder.

Open terminal and run: flutter doctor -v

That works for me.

Quang Duong
  • 161
  • 1
  • 5
  • 2
    may also create a soft link `ln -s "/Applications/Android Studio.app/Contents/jbr" "/Applications/Android Studio.app/Contents/jre"` – ken Feb 27 '23 at 09:37
  • 1
    Best answer for 2023 – Rahul Kushwaha Mar 23 '23 at 04:42
  • In my case Go to Applications -> right click on Android Studio -> choose "Show Package Contents". -> Contents -> Create folder named jre (not .jre) -> copy Contents folder from jbr to our new folder jre – Razmik Gharibyan Mar 31 '23 at 09:48
2

I encountered this issue because I didn't have Java installed. If you can't see a Java icon under System Preferences, Java 7 or later versions is not installed. Link to java.com

Sharon Atim
  • 1,777
  • 16
  • 12
2

2022 First of all, check out did you install Java on your mac. After that I suggest to install Java 19. If you finish this step

on command pannel : nano .zshrc add the below code to the bottom of file;

echo 'export JAVA_HOME="$(/usr/libexec/java_home)"' >> ~/.zprofile
echo 'export PATH="$HOME/.daml/bin:$PATH"' >> ~/.zprofile

That is all. You are good to go.

algor
  • 67
  • 2
1

I was able to fix my issues by doing the following, I sync my project with Gradle files

I downloaded Java 8 (but I don't think this guy did the work)

Zionnite
  • 291
  • 4
  • 13