Android Studio suddenly not running Flutter/Android application on phone anymore - android
Problem
I'm trying to run my Flutter app on my phone, connected via USB, in order to debug.
It stopped working from one day (May 13, if it matters) to the next. Quite frustrating is that I made no changes since it last worked. Since the last time I clicked the Android Studio "play" button on May 13, there were only code changes, which all ran fine via hot reload. Then the next day when pressing the play button, it suddenly complains about JAVA_HOME not being set.
After some troubleshooting, I now get the error message
* What went wrong:
Execution failed for task ':camera:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError:
class org.gradle.internal.compiler.java.ClassNameCollector(in unnamed module #0x3d2880e7)
cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler)
because module jdk.compiler does not export com.sun.tools.javac.code
to unnamed module #0x3d2880e7
New lines inserted for readability. Also, the recent code changes do not concern camera usage in any way.
No problems when building for Chrome instead of Android.
Troubleshooting attempts
Android Studio version
With me not having changed any configuration manually, my first suspicion was something must have changed automatically. I have Android Studio installed via the JetBrains toolbox, which is set to automatically update my IDEs when a (stable) update is available. The last update (4.2.1) was indeed released this month, however rolling back to the previous version 4.2.0 did not fix the issue.
Pre-existing Java
Well... JAVA_HOME was set. Noteworthy is that it was set to the Android-Studio-embedded version of an older, non-JetBrains-Toolbox installed Android Studio. Even more noteworthy, it was set to
C:\Program Files\Android\Android Studio\jre, while the actual installation was under
C:\Program Files\Android\android-studio. Lowercase probably does not matter on WIN10, but the hyphen does... this was never supposed to work.
Making a copy of the folder under C:\Program Files\Android\Android Studio did not resolve the issue. Flutter doctor said it can find Java, but can not execute it. The play button in Android Studio produced another error now, but I don't know which anymore and I can't reproduce that anymore since I got rid of those old folders by now. Well, that was a dirty hack anyway.
That running echo %JAVA_HOME% in a windows CMD printed the path, while the terminal in Android Studio just printed %JAVA_HOME% added to all the hilarity. At that point I decided that this is too messed up and I'll just start over from the beginning.
New Java
So I uninstalled Android Studio, removed all Java installations could find, and removed JAVA_HOME from the environment.
After a reboot, I downloaded Android Studio again => no luck.
In Android Studio, went to File => Project Structure..., which lead to a different screen than where it now always leads me to, where I was able to select the SDK to use, but also edit the list of SDKs to choose from (JDKs and Android SDKs). Selected the "download JDK" option there => no luck
In the same screen, added OpenJDK jdk-16.0.1 downloaded manually to C:\tools\ => no luck
Adding JAVA_HOME again, set to C:\tools\jdk-16.0.1 => Android Studio terminal now finally prints this for echo %JAVA_HOME%, but building the project still no luck
Now currently, File => Project Structure... leads me to a window where I can select, separately, Android SDK location (set to C:\AndroidSDK\Android-sdk), Android NDK (nothing selected) and JDK. For the last option, I tried the embedded JDK as well as JAVA_HOME (still jdk-16.0.1 in C:\tools\) => no luck, both produce the IllegalAccessError I mentioned earlier.
I found some (years-) older posts mentioning that Android Studio doesn't work with newer JDK versions, but I get the same error with the embedded version.
Question
What the heck is going on?
Why does it stop working form one day to the next without changes?
And what does it want form me to start working again?
Updates
Update 1
Thank you Milan Chauhan! After removing the folder .idea and android\.gradle, and then doing File -> Invalid cache and restart, building now produces another error:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path
accessible: module java.base does not "opens java.io" to unnamed module #5689f0e
When I create a completely new flutter project and click the play button, I get the error
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Could not open proj generic class cache for build file
'C:\repos\flutter_new\android\app\build.gradle'
(C:\Users\Raphael\.gradle\caches\6.7\scripts\c0x6i1v1trom5wonrdzhz34dy).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_'
Unsupported class file major version 60
I managed to fix it with these steps:
Download OpenJDK 15.0.2 from here https://jdk.java.net/archive/
Put it under C:\tools\
Set JAVA_HOME to C:\tools\jdk-15.0.2
It seems that something here (Android Studio 4.2.1 / Dart 2.12.3 / Flutter 2.0.6) is indeed not compatible with JDK 16.
I still don't know what exactly happened here. Facts are
The Android Studio update came out very recently, and it's the only thing I'm aware of that would change on its own.
My own, manually added JAVA_HOME works with JDK 15, but not with JDK 16.
Choosing the embedded JDK, I get the same error as with manually added JDK 16.
My best guess based on that is that Android Studio did update automatically and that updated the embedded JDK to version 16.
Delete .gradle folder and .idea folder from the project root folder
In Android Studio, File -> Invalid cache and restart
Related
Error about Android Studio on Macbook M1: An error occurred while trying to compute required packages
I've downloaded Android Studio from the official website, the one for M1 chip (arm). Basically running it for the first time, the error is the following: An error occurred while trying to compute required packages I was searching about it the whole day to figure out a way to make Android Studio work, but that error keeps showing. Not completely sure if it's related to M1 Macbook, as on my Intel one it works as expected. What I already tried to do: Installing the command line tools, then placing it on SDK folder (Users/user/Library/Android/sdk). Then added the bin to the PATH (Reference) After doing that, when executing the sdkmanager on terminal I get the following message Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli Then I searched again and it leaded me to this thread, then as on the answers I tried to rename the folder, then other tries not related. I fell into many links and references that did not work at all. After that I try to check what happens if I click on New Project, then the following is shown: The Android SDK location cannot be at the filesystem root As the message indicates, the issue is The Android SDK location cannot be at the filesystem root, so I searched again about it I looked into that and got to a few links, for example this one and this one. Before doing that search I clicked on the Edit button, which lead me to the Android SDK to be updated/installed (Nice!), so I had to delete the content I had on Android folder (inside Library) and clicked next...then, I got the same message An error occurred while trying to compute required packages. Then I thought "ok, maybe if I change the SDK location", so I changed to ../Documents/sdk, which ended up in the same result Seems like no matter what I do, it ends up showing up that same message. When I run java -version that's what I see: java version "1.8.0_311" Java(TM) SE Runtime Environment (build 1.8.0_311-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode) Did anyone have the same issue? Am I doing something wrong? Not sure how to proceed from here, despite of the Android Studio version I download it's always the same result. Any help is appreciated.
This is what solved it for me on my M1. Go to Android Studio Preview and download the latest Canary build for Apple chip (Chipmunk). Don't worry this is just to get through the initial setup. Unpack it, run it, let it install all the SDK components, accept licenses, etc as usual. Once it's done, simply close it and delete it. Now when you start your stable Android Studio (Arctic Fox) you should not see the error.
I tried over a dozen 2021 stable and Canary builds from https://developer.android.com/studio/archive and couldn't get any of them to work. This is the only thing I could find that worked: Download, unpackage and run Android Studio 3.6.3 android-studio-ide-192.6392135-mac.zip from here. Proceed through the initial setup and let it download and install the SDK. Ignore any errors at the end. Delete this version and open the stable Android Studio like normal. You can now proceed through setup!
I also faced this issue a couple days and I changed my mind to not use Android Studio. And It's fixed! My alternative option is to download IntelliJ community edition and install Android SDK to your machine. Image for IntelliJ Download Page After (IntelliJ) installation is complete, You need also to create new project, select android then download SDK. (thanks for #SteveRoger 's comment) then open Android Studio again and follow its setup wizard. It will show that my machine has been already installed Android SDK and it can run perfectly at this time. Hope this is an alternative solution for you. Have a great day.
I solved the problem with these steps: Install the old Android Studio 3.6.3 (find the old Android Studio at https://developer.android.com/studio/archive) Install the Android SDK Overwrite the installation with the Apple Chip version of Android Studio
I had the same problem with my MacBook air(m1 chip) as you mentioned. How did I solve it? Just download the IDE - Intellij IDEA and create a new project, select Android Project and there download Android SDK, now you can install android studio again and the sdk is installed.
I've also had this exact same issue when downloading Android Studio 7.0.3. Here's what helped me. Download the command line tools, place them in the SDK folder (e.g., on mac: /Users/user/Library/Android/sdk), and then add the bin folder to the PATH. Install the latest platform: in a terminal, execute ./sdkmanager "platforms;android-31" Next up execute this command ./sdkmanager --channel=3 emulator (this switches the channel from stable=0 to canary=3 ) Open Android Studio, and go to the SDK Manager (Appearance and Behavior > System Settings > Android SDK) Click on "Edit", and then select the sdk folder. Then "Next" > "Next" > "Finish". Now restart Android Studio and everything should work
I had the exact same error as OP. Follow what Art Fedorychak mentioned, it worked for me as well. It seems like the current stable build of the Apple M1 android studio version doesn't actually initialize an SDK if one doesn't already exist, but it seems to be able to update and or / initialize one that does as long as the same folder is being referenced, so we just need to use a working SDK for M1 on the initial run and then revert back to the stable AS
This is what solved it for me: Download & install IntelliJ IDEA. https://www.jetbrains.com/idea/download/#section=mac Open IntelliJ IDEA and create New Android Project Download sdk success Open Android Studio & checked it worked
My solution to this problem is simply to put the SDK in another location. For myself, I put the SDK folder to subfolders in Documents. The SDK download will initiate.
Xamarin Android XamarinBuildAndroidAarRestore task could not be loaded from Xamarin.Build.Download
After upgrading all of my Xamarin Android nuget packages to the latest versions, I am now getting the following build error: /Users/justintoth/.nuget/packages/xamarin.build.download/0.4.11/build/Xamarin.Build.Download.targets(116,3): error MSB4062: The "Xamarin.Build.Download.XamarinBuildAndroidAarRestore" task could not be loaded from the assembly /Users/justintoth/.nuget/packages/xamarin.build.download/0.4.11/build/Xamarin.Build.Download.dll. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. I've seen other references to this error and those devs were able to clean the solution, quit and restart Visual Studio for Mac, or reboot their computer. However, I've tried all three of those, manually deleting the bin / object folders, and even reinstalling Visual Studio for Mac and still am hitting this build error.
I manually installed the latest Xamarin.Build nuget package and now it works. Not sure why it wasn't required before and now it is, but glad it was an easy fix...
Gradle won't pick up Android build tools unless opened in Android Studio
I'm preparing an Android build pipeline in Jenkins, on a Windows build server. Jenkins uses a number of workspaces and will often re-use them. I've noticed that when Jenkins re-uses a workspace, there are no problems and a build goes perfectly. But when it first checks out a new workspace, the gradle wrapper complains that it cannot install Android build-tools. The build tools (the exact version) are already installed. I can open another older workspace and run the gradle build in there and it works perfectly and then, with the same login and in the exact same cmd session, go to the new workspace and run the same command and it complains that it cannot install Android build-tools. A note about the Android configuration: I'm storing the Android SDK in C:\android-sdk\ and have given every user access to that directory. ANDROID_HOME and ANDROID_SDK are set as system-wide variables. This is the most convenient solution- this way every user that logs in, domain account or otherwise, is (in theory) able to immediately build the solution without having to set up their own SDK, and we don't end up with a lot of duplicated SDK data. I can fix the issue manually by opening the workspace folder in Android Studio. Just doing this alone seems to fix the issue. My hypothesis is that somewhere there's a cached value in the project metadata telling gradle where to find the Android build-tools, and when I open Android Studio it updates this value. Obviously the work-around isn't adequate because the build needs to work consistently every time without human intervention. Is there some command I can use to refresh this cache? Or perhaps some configuration files that are checked into git that shouldn't be?
Figured it out. Gradle looks in two places, in order of priority, for your SDK: Firstly, it checks whether a local.properties file specifies the SDK. Then, it tries the ANDROID_HOME (not ANDROID_SDK) system variable. Opening a folder in Android Studio generates the local.properties file, which is why that work-around worked. I had no local.properties file, but my ANDROID_HOME was set to the Android Studio install folder rather than the Android SDK. When I moved it to the SDK and re-started the Jenkins agent service it worked.
Android Studio starts downloading gradle
I have downloaded android studio and sdk and everything required but when I start a new project studio starts downloading gradle which is already downloaded with android studio. If I try to stop that download, it can't be stopped, I need to shutdown my laptop. Please tell me why this happens! And if I import any project then it shows a message that gradle build failed and tells me to install build tools API Level 7 which NOBODY uses now a days. What's wrong with this studio?? I am using Ubuntu 14.04, .gradle directory of my home folder has files of more than 300 Mb I don't understand what this android studio keeps downloading. Please help me fixing this problem
That is normal one time download of maven gradle dependencies and packages. However it usually takes a long time to download and build. Not sure what are the reasons for this. Android studio contains gradle essentials, but for some reasons that is insufficient to run command line tools. There is a workaround to skip this download by adding gradle repo directory to android studio settings (Configure --> Settings --> Gradle). You have to manually add GRADLE_HOME to the system PATH variable according to your operating system. Run gradle-v in command line to confirm everything works right.
Android Studio Can't Find JDK Mac
I'm just trying out Android Studio. I imported a project from Eclipse, but every time I try to run it I get this error: "Cannot run program "Library/JavaVirtualMachines?jdk1.7.0_10.jdk/Contents/Home/bin/java" (in directory "/Users/myname/Library/Caches/AndroidStudioPreview/compile-server"): error=2, No such file or directory. I just installed the latest JDK using the JDK 7 Update 21 dmg. Is it installing the jdk in a place where Android Studio won't find it? The dmg didn't have any options for where to install the jdk other than "Install for all users of this computer," which I did. When I was using Eclipse I had no problems with running my programs. Furthermore, the Project Structure option was no longer available after I updated earlier today. Instead I just get the message, We will provide a UI to configure project settings later. Until then, please manually edit your build.gradle file(s.)" I'm not sure what to do to get my programs running again. Do I need to locate the jdk files and move them? Could I tell Android Studio where the files are actually installed?
The solution was easier than I thought: just go to File/Other Settings/Default Project Structure and click SDKs. There the JDK home path can be changed.
Yes changing the JDK path will work. If that doesn't fix your problem, as it didn't for me at first, uninstall your JDK and redownload and install it. Once I reinstalled mine, it worked flawlessly.