Execution failed for app:clean in android studio 2.2 - android-studio

I currently switch to android studio 2.2 and I have a big problem. when I build project to deploy on emulator I got this error:
Error:Execution failed for task ':app:clean'.
> Unable to delete directory: /mnt/D/Document/WorkSpace/Android/Test/app/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/25.0.0/jars
I clean that path and again it tell me that:
Error:Execution failed for task ':app:clean'.
> Unable to delete directory: /mnt/D/Document/WorkSpace/Android/Test/app/build/intermediates/exploded-aar/com.android.support/cardview-v7/25.0.0/jars
I clean it handy and again:
Error:Execution failed for task ':app:clean'.
> Unable to delete directory: /mnt/D/Document/WorkSpace/Android/Test/app/build/intermediates/exploded-aar/com.android.support/support-compat/25.0.0/jars/libs
I don't know how many steps exists and if I pass all these steps, may be I mentally!
I don't have these issues in android 1.4. is this a bug about android studio or related to my system(Arch Linux)?
Thanks in advance.

Disable Instant Run. It is in
File -> Settings -> Build,Execution -> Instant Run
This worked for me.

For me there was a stuck debug test inside of Android Studio and mockable-jar was used inside of that JVM and couldn't be deleted.
What I had to do is.. stop the frozen JVM from Task Manager, then clean.
What I'll do the next time this happens is.. stop the frozen debug test from Android Studio, then clean.

i finally fix it!
after:
apply plugin: 'com.android.application'
add this line of code to build.gradle(Module: app) file:
task clean(type: Delete) {
delete rootProject.buildDir
}
it will delete all jar and lib files from build your directory.
hope to enjoy :)

Related

Sync failed and "Unable to find Gradle tasks to build" after upgrading from Android Studio 2021.3.1 to 2022.1.1

I found several SO posts describing similar issues, but they are outdated and none were found to be helpful in regard to my upgrade to the latest version of Android Studio.
After upgrading my Android Studio from version 2021.3.1 to version 2022.1.1, my attempt to File > Sync Project with Gradle Files results in Sync failed (within less than 200ms).
When I try to Build > Rebuild Project, I get the following error:
Unable to find Gradle tasks to build: [:].
Build mode: REBUILD.
Tests: None.
There is no :app in any of my settings.gradle files.
I did File > Invalidate Caches... (all of them) and restarted AS, but this didn't help.
I also deleted all build folders, but this didn't help.
Any idea how to solve this?
Right-clicking the Sync failed to Reload Gradle Project results in the same failure but it opens now a bar on top of the editor window with the Show Log in Explorer link. When I click it, I indeed find idea.log in C:\Users\WebViewer\AppData\Local\Google\AndroidStudio2022.1\log. I am inspecting it now...
Update:
The first thing I noticed in idea.log is the following exception:
org.gradle.tooling.GradleConnectionException: Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-bin.zip'.
...
Caused by: org.gradle.internal.jvm.JavaHomeException: The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe
Thanks to this SO tip, I did mklink /D "jre" "jbr" which all of a sudden revived Android Studio and started to download lots of Gradle related packages.
I still have "Gradle Sync issues" but at least Android Studio prompts me now how to solve them:
but... according to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, why is Android Studio asking for a minimum of 7.5?
Problem solved.
For the benefit of all, I am posting here a summary of what I did to solve it:
When a laconic "Sync failed" is all Android Studio provides, C:\Users\<yourname>\AppData\Local\Google\AndroidStudio2022.1\log\idea.log is key to finding clues to the mystery.
In my case, it was failure to find and run the embedded Java version. So, I did mklink /D "jre" "jbr" which miraculously revived the build process (see https://github.com/flutter/flutter/issues/106674#issuecomment-1381685888).
Under File > Settings > Build Tools > Gradle, this is the Java version that works for me:
I then tried to follow Sync's output to use Gradle 7.5.0. It could not be found on any of the repositories in my top level build.gradle and resulted in chasing my tail... According to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, so I reverted to using it (why didn't it work the first time, I don't know) and here is my working top level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1")
classpath("org.mockito:mockito-inline:4.11.0")
}
}
allprojects {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

Android Studio fails to clean project

Android Studio is creating strange files, which cannot be deleted.
Error:Execution failed for task ':app:clean'.
Unable to delete directory: F:\VWA2\app\build\intermediates\transforms\instantRunSlicer\debug\4\uk\co
These are the files. My question is, why they are even created and how this can be fixed.
Thank you!

Kotlin app build failed due to "Could not initialize class com.intellij.ide.highlighter.JavaFileType"

I've just updated Android Studio to 2.2 and now my Kotlin project won't build. The gradle synch works fine, but when attempting to build I'm immediately presented with an error that reads:
Error:Execution failed for task ':app:compileDebugKotlin'.
> Could not initialize class com.intellij.ide.highlighter.JavaFileType
I've checked that my Kotlin plugin is up to date. This error sounds like something to do with the IDE and highlighting Java code? Any help would be appreciated.
Open Tools | Kotlin | Configure Kotlin Plugin Updates in the main menu,
then choose Check for Updates. Be sure that yo're using Stable channel.
Close Android Studio, go to your project's directory, and delete build and app/build folders. Run Android Studio. Deleted folders would be recreated.
Hope it will help
In my case the kotlin plugin was not updated as #piotrek1543 said in other answer.
In addition to that the build.gradle had an old Kotlin version number 1.0.1-2 and the IntelliJ said in a warning on top of to switch to the current bundled version 1.0.4.
Now with the kotlin version like this the error is gone:
ext.kotlin_version = '1.0.4'

Exclude compiling mockable Android jar

I noticed that my android studio automatically adds a grade task :mockableAndroidJar. Is there a way to exclude this task from automatically happening.
I want to do this in hope that it might speed up the Gradle build step.
You can exclude that task from running when doing a Gradle build as follows:
gradle build -x mockableAndroidJar

Android Studio include maven artifact in APK (gradle)

I have an Android project that requires the Jsoup library. I've tried everything I can think of to get the jar shaded into the APK.. I just can't get it working. Logcat tells me:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.jsoup.Jsoup
Does anyone know how to include/shade a maven artifact into an APK with Android Studio?
I have found the answer. The trick is to append ":sources". See an example here: http://www.alonsoruibal.com/my-gradle-tips-and-tricks/
I have seen the same type of error every time someone else adds a library with Gradle. Build is usually successful but app crashes when it tries to use the new library. Running task clean with Gradle helps.

Resources