Android Studio build cannot delete path - android

I always have this in my Android Studio Windows 10. Every time I build my project and it just throw this.
Execution failed for task ':kruso:transformClassesWithDesugarForDevDebug'.
> com.android.build.api.transform.TransformException: java.io.IOException: Could not delete path 'C:\Users\Admin\Desktop\source_code\android\googleplayapps\Kruso\kruso\build\intermediates\transforms\desugar\dev\debug\0.jar'.
I tried several solutions i can find in stackoverflow but none works as expected. Here are the things I tried:
Deleting the build folder (Not working, Windows complain the folder or file is being used by another process)
Clean and rebuild project (Sometimes works, sometimes will still complain could not delete path. This is not applicable since it would take long time, ~4mins, to rebuild. If using Instant Run, it would just take 45s)
Restart Android Studio (This works, but restarting Android Studio for every build is just taking too much of time.)
p/s I'm using a Windows 10 powered by Intel i5-7200U, 12GB RAM, Android Studio 3.1.2

Simple Close the Android studio goto project Location and delete the folder from File explore, without starting an android studio.
If needed restart system and without starting any other program, goto project location and delete the folder.

Related

Android Studio suddenly not running Flutter/Android application on phone anymore

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

Run button isn't compiling project in Android Studio 3.1 [duplicate]

When I try to install an app, there are two possibilities:
Install existing APK from build folder when I run the app
Install APK after performing clean build
For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:
The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.
NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder
I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.
Things I've tried:
Running the app when APK file exists in the build folder (works perfectly fine)
Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
Same process of cleaning and running the app after doing Invalidate Caches/Restart
I have solution for your issue.
Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768
Edit your app configuration as below.
Here you can see your app configuration as below.
Here is missing Gradle-aware make attribute in before launch configuration. You can see here.
Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.
You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.
It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.
Note : This issue is resolved in new Android Studio 3.1.1 Stable release.
The APK file
/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not
exist on disk.
May be bug. You should change Settings.
You should open the Run/Debug Configurations dialog & select Run > Edit Configurations
Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.
Note
If you receive
Shutdown finished in 0ms Error while generating dependencies split APK
com.android.ide.common.process.ProcessException: Failed to execute
aapt at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
at
com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)
You should Un-Check INSTANT RUN.
File-- Settings-- Build, Execution, Deployment -- Instant Run and
uncheck Enable Instant Run.
clean your project and run again
If it's not work then
Step 1 Close your project.
Step 2 Go to your project folder and delete all build folder.
Step 3 run your project.
This issue has been fixed with Android studio 3.1.1 (April 2018) release.
Update your android studio to 3.1.1.
Here is there explanation regrading the issue details, cause and solution:
In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.
To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.
Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0
For all people seing this and having the issue on Android Studio +4.0.0:
Run -> Edit configurations... -> disable check box (Allow parallel run)
It may slow your build a little but it better than running the app more than one time.

Android Studio 3.1 is not compiling/building the app, runs instantly [duplicate]

When I try to install an app, there are two possibilities:
Install existing APK from build folder when I run the app
Install APK after performing clean build
For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:
The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.
NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder
I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.
Things I've tried:
Running the app when APK file exists in the build folder (works perfectly fine)
Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
Same process of cleaning and running the app after doing Invalidate Caches/Restart
I have solution for your issue.
Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768
Edit your app configuration as below.
Here you can see your app configuration as below.
Here is missing Gradle-aware make attribute in before launch configuration. You can see here.
Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.
You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.
It will solve this old apk installing issue on clean build in new Android Studio 3.1 issue.
Note : This issue is resolved in new Android Studio 3.1.1 Stable release.
The APK file
/Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not
exist on disk.
May be bug. You should change Settings.
You should open the Run/Debug Configurations dialog & select Run > Edit Configurations
Make sure, Gradle-aware Make is Added in TaskList or not. If not then click + & select from the options.
Note
If you receive
Shutdown finished in 0ms Error while generating dependencies split APK
com.android.ide.common.process.ProcessException: Failed to execute
aapt at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:809)
at
com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:797)
at
com.android.build.gradle.internal.transforms.InstantRunSplitApkBuilder.generateSplitApkResourcesAp(InstantRunSplitApkBuilder.java:373)
You should Un-Check INSTANT RUN.
File-- Settings-- Build, Execution, Deployment -- Instant Run and
uncheck Enable Instant Run.
clean your project and run again
If it's not work then
Step 1 Close your project.
Step 2 Go to your project folder and delete all build folder.
Step 3 run your project.
This issue has been fixed with Android studio 3.1.1 (April 2018) release.
Update your android studio to 3.1.1.
Here is there explanation regrading the issue details, cause and solution:
In some cases, when a project created in Android Studio 3.0 was opened for the first time in Android Studio 3.1, the Gradle-aware Make task was removed from the Before launch area in Run/Debug Configurations. The result was that projects did not build when the Run or Debug button was clicked, which in turn caused failures such as deployment of incorrect APKs and crashes when using Instant Run.
To solve this problem, Android Studio 3.1.1 adds the Gradle-aware Make task to the run configuration for projects that are missing this entry. This modification occurs after the first Gradle sync when the project is loaded.
Official release notes: https://developer.android.com/studio/releases/index.html#3-1-0
For all people seing this and having the issue on Android Studio +4.0.0:
Run -> Edit configurations... -> disable check box (Allow parallel run)
It may slow your build a little but it better than running the app more than one time.

setup jdk error in android studio Error in Java

this image is android studio error in java editor
this is happens after windows Updating and restarting in Windows 10.
my pc restart automatically for updates and then i saw this errors in android studio.
when i use Ctrl_space for hint it shows "setup JDK"
Ctrl+space for hint
when i click on it popup will display with "select SDK".
after select and restart got same error lines.
this red lines are in all projects.
i tried it with gradle sync and pc restart and android studio restart.
please help me to solve this.
fixed --
This Problem happens when
Android Studio unexpectedly closed or stopped due to power cut or
force stop from Task Manager many reasons.
Solution for this Problem is invalidate caches and Restart Android Studio. No need to reinstall Android Studio or JDK. if error is Gradle related than Go to .gradle folder in Project root folder and delete it and regenerate the gradle file using re-sync.
I think you need to reconfigure location of JDK as it was changed after update and IDE can't find it in last location. Remove SDK config from IDE and add it back.
Re-configure your System Variables. The system somehow lost the variable pointing to your JDK or the JAVA_HOME

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.

Categories

Resources