How to fix Android Studio getting stuck executing Gradle tasks? - android

Android Studio (Beta) 0.8.6 gets stuck when I try to build/run the project, as well as clean it. It stays responsive, but the Gradle: Executing Tasks message doesn't disappear (longer than 20 minutes is when I give up) and the app never runs.
This is what I attempted:
Invalidate caches/restart
Force quit and restart
Remove it from Applications (on Mac) and re-download it from the official website.

Fixed it by going to Android Studio -> Preferences -> Gradle -> and ticking Offline work. Still have no idea what was wrong, but at least now it compiles.
Edit:
In new Android Studio Versions the path is File -> Other Settings -> Default Settings -> Build-Excecution-Deployment -> Gradle

The question seems old but in case anyone need it.
I have just faced this problem recently, after a fresh Ubuntu 14.04 installation.
After google for a while with no luck i checked the terminal, it turned out that libz.so.1 is missing. So i installed it, worked like charm.
Installing instruction here:
libz.so.1: cannot open shared object file

Enable Offline Work from Setting

This can happen for lots of reasons. So instead of giving an exact fix, here are some steps to help isolate the cause.
Run the gradle command from command line. Does it still fail?
$ ./gradlew myTask
If so, re-run with debug flag. Any useful info?
$ ./gradlew myTask --debug
If it's just hanging, try getting a stack trace. Search the dump file for myTask
$ jps -mv | grep Gradle <--- be sure to use capital "G"
2290 GradleDaemon 3.3 -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2304M -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant
$ jstack -l 2290 >> dump.txt <--- your process ID will be different
If it's only hanging when running Android Studio, generate thread dump for Android Studio read more here.

You have to add execution mode to the file: AndroidStudioProjects/YourProjectName/gradlew so that Android Studio can execute it.
if you are on a linux machine use this command: chmod +x gradlew
to run this command you may need to have administration privileges. in Ubuntu you can use sudo chmod +x gradlew to do that

In my case looks like gradle was missing 32 bit library on a 64 bit Ubuntu 16.04. Doing sudo apt-get install libstdc++6:i386 resolved the problem.

This happened to me after adding google play api to dependencies{}. ./gradlew app:assembleDebug showed an error saying something like Dex ID limit reached use multi-dex. just as I was setting it up as described here, I decided to remove the dependency I recently added and the issue was gone.
Google also suggests using proguard as a technique to optimize the number of Dex IDs in the same document.

For GNU/Linux Users:
I copied the SDK from another storage to my home directory. Then I was getting stock gradle build running. The problem was the permissions of SDK files. Watch the gradle console log and if you see some permission denieded stuff, then do the following - give all the files executing permission by this command:
chmod -R +x /path/to/android-sdk

After a lot of struggle and following all solutions posted above (and in similar posts) I finally found that the problem on my PC was the antivirus application. I disabled it and gradle refreshed and built fast, as it did before the problem started.
It looks like my antivirus recently started blocking gradle from updating/downloading necessary information from the Internet and that is what is causing the delays and eventually timeouts in loading and refreshing a project. Disabling the antivirus it corrects the problem, every time.

I have centos 7 64 bits installed on a virtualbox 5.0.16 virtual machine and gradle version 2.10 with Android Studio 2.0
The log file of gradle is located at $HOME/.gradle/daemon/2.10
Log file: daemon-<some number>.out.log
By inspecting this log file I found out that libz.so.1 was not found by aapt.
Despite that command "locate libz.so.1" output was
/usr/lib64/libz.so
/usr/lib64/libz.so.1
/usr/lib64/libz.so.1.2.7
aapt was not able to find it.
In order to solve the issue I had to execute
yum install zlib.i686
After that Gradle started working as a charm.
Good luck!

I had something similar.
When I ran gradle from the command like it would throw this exception
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDevDebugJavaWithJavac'.
after waiting at this line for like 25 minutes
:app:compileDevDebugJavaWithJavac
it turned out to have something to do with the android annotations I was using. I replaced the
#UiThread
I was using with
activity.runOnUiThread(new Runnable(...
And it started to compile just fine. Its weird because I was using the #UiThread annotation in lots of other places in my code.

In my case, I was getting this error by the Gradle Builder (Android Studio 2.2, Windows 10)
java.lang.RuntimeException: Timed out while waiting for slave aapt process, try setting environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds
The solution was just to add the variable SLAVE_AAPT_TIMEOUT to my Windows environment, and set it to 30

I was with the same problem and solved setting variable SLAVE_AAPT_TIMEOUT in System Variables with the value 30.

I'm on Windows, and I had the same problem.
For me, the gradlew executable somehow got deleted, no idea how. I'm on the Canary, and I've had the issue before.
In the terminal window on Android Studio, type gradlew and it will redownload and install it if it's missing. (My old solution was a complete reinstall of Android Studio, so this is easier)

I had the same problem, even with new standard projects (Ubuntu 16.04). The problem turned out to be in third-party dependencies of the Gradle. View the file:
~/.gradle/init.gradle
It may contain additional dependencies, which the Gradle can not load.
You can see what can not be loaded in the console:
./gradlew --debug

If you use realm library and use RealmStudio or RealmBrowser to open file .realm, make sure you perform delete file .realm/lock and folder .realm.management.

I think java.exe is the reason of this issue. Just manually kill this application and try. It really worked for me using Android studio 3.0.1.

In my case it was stuck on mergeDebugResources because I accidentally had a double-escaped single-quote \\' in a string. Android Studio doesn't mark this as an error, but instead gets stuck building!

Related

Android Studio: R.jar: The process cannot access the file because it is being used by another process

After a new installation of Android Studio 3.6.3 (portable). When I try to build and run my project, I keep getting
app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar:
The process cannot access the file because it is being used by another
process.
Not sure what it wants from me. I run Android Studio "as administrator" and even closing the project and reopening it, the first time it runs, the second time I get the error.
I tried invalidate caches and restart, I tried deleting folders under app/build but it seems to come back. What am I missing?
Thanks
Update:
When trying to clean the project, I get the following
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:clean'.
> Unable to delete directory 'C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build'
Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
- C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar
- C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug
- C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar
- C:\Users\name\Downloads\portable\android-studio\projects\appm\app\build\intermediates
If I wait for several minutes, for example, the time it took me to update this question, then it works again...
update:
Updated to Android Studio 4 and the same problem occurs.
Try
taskkill /im java.exe /f
in cmd (windows 10)
I encountered the same problem but on Android Studio Arctic Fox while working on a Jet Compose project.
I simply changed the run configuration and the build error was resolved.
Change DefaultPreview to app and the issue is resolved.
Killing the "OpenJDK Platform binary" process from Task manager worked great for me.Thanks to Abed Murad, which I saw on his link. (I have no reputation to cast a vote yet - my bad!)
It's an internal bug in AS, I reported it as a bug, you can follow up here
https://issuetracker.google.com/issues/167701947
I used to try to delete the file R.jar on ...\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug and when it's locked, I had to close Android Studio then delete R.jar before reopening the Android Studio.Is it (killing the "OpenJDK Platform binary") the best solution? I don't know, however, it's what I got for now. Once I get a better one, I'll update it. Luck there guys!
It's an internal bug in AS, I reported it as a bug, you can follow up here
https://issuetracker.google.com/issues/167701947
Try removiong all *.xml files from %USERPROFILE%\AppData\Roaming\Google\AndroidStudioPreview2020.3\workspace
I figured it out from this google issue.
I had the same issue all I did remove R.jar and re build my project.
Invalidate cache and restart solved my problem

Gradle gets stuck at either 'build' or 'assembleDebug' when using the 64bit or 32bit version of Android Studio

The issue I've had over the past few months is that Android Studio would often get stuck on Gradle: build, as seen here. Android Studio itself would stay responsive but the build simply wouldn't progress. It also never generates any kind of error, so I can't really post any useful information. Once in a blue moon it might suddenly work, but nothing reliable.
Recently I found a post here on Stack Overflow where someone's Android Studio would get stuck on Gradle: build when he tried to create a new project, and he noticed that this issue didn't exist in the 32-bit version of Android. So I thought, why not try that. Turns out that building isn't an issue anymore, but assembleDebug is, when trying to build the application. As can be seen here.
Of course all these commands work flawlessly when run using command prompt and gradlew.
What I've tried so far:
Reinstalling Android Studio (including the removal of .AndroidStudioProject)
Upgrading Android Studio to the latest version
Removing any build files from projects
Creating completely new projects in Android Studio
Switching from 64-bit to 32-bit Android Studio
I'm running the latest version of Android Studio, using version 19.1.0 of the build tools, gradle v0.11+ and am on Windows 8.1.
Is there anything else I can try? This is starting to become seriously annoying. The last possible solution I can come up with is just doing a complete format and a fresh Windows installation.
I was experiencing the same problem, and the solution was very unexpected in my case: AVAST antivirus was somehow interfering with the Gradle:build process.
Deactivating this antivirus solved the problem!
Because there is no answer to this problem I will share, what I have done, to solve this issue. From what I have seen, the problem is that there is a dependancy(or many) from a maven repo that can not be loaded. So you have to take all dependacy one by one and check if exist on the maven repo.
For example I was having a dependancy for "org.jraf:android-switch-backport:1.3.1" from "http://JRAF.org/static/maven/2" that at that time could not be opened.
My build.gradle looked like this:
repositories {
mavenCentral()
maven {
url "http://JRAF.org/static/maven/2"
}
}
compile "org.jraf:android-switch-backport:1.3.1
For me, this problem occurred when I was USB tethering using an Android device. The first build took anywhere from 5-10 minutes, and every subsequent build took about 3-7 seconds. I found that by disabling USB tethering, the first build completed quickly (and so would all subsequent builds). After the first build completed, I could reenable USB tethering.
If you have a fresh Ubuntu 14.04 with Android Studio 1.5, you may be missing a library. Try this:
sudo apt-get install lib32z1
Another stack overflow answer
It happens 1 in 2 times for me. The hack that works for me is File->Exit and confirm exiting. Then a message shows up telling me that Gradle is running and then all of a sudden the screen to choose the device shows up. I Click NO and all goes well again.
Anyway, still a bummer, but I have not found an answer yet.
My problem was that the Android Sdk executables were missing the executable bit. You can check some of your binaries like /Sdk/build-tools//aapt to see if they have permission to execute. If not you can solve it by running this on the Sdk folder
chmod -R +x ./
If you are behind a proxy on ubunthu you might need to set your gradle system wide proxy:
sudo nano ~/.gradle/gradle.properties
And enter the following entries:
systemProp.http.proxyHost=<Your Host>
systemProp.http.proxyPort=<Your Host Port>

Configuring Android to use in terminal for Linux Mint

I am currently using Eclipse to develop Android apps. Following the Android Developer tutorial, they had the option to program using the command line. I am interested in doing it this way but ran into a number of errors. I have tried several solutions available on the internet and I fear that I might have added to many things on my PATH file. None of the solutions have worked for me.
I am very lost with all these directories. Please help for Linux Mint specific distribution.
Key errors to address are:
android: command not found
and
ant debug
Buildfile: build.xml does not exist!
Build failed
I downloaded adt-bundle-linux-x86-20130717.
Update:
I think I managed to get the android command working by hardcoding the following on my bash.bashrc:
/etc/.../sdk/tools
/etc/.../sdk/platform-tools
Please let me know if it is recommended to do this another way.
However, ant debug is still not working.
If ADB is properly in your path, the android command should launch the SDK updater. Here is what I have in my .bashrc
# SDK
PATH=${PATH}:~/android-sdk/tools
PATH=${PATH}:~/android-sdk/platform-tools
You put the environment variable configuration in which files? configuration is completed, use the source command to run the file, or try to restart the computer

Exporting APK from eclipse (ADT) silently crashes

Every time I try to export an APK from Eclipse (tried Juno and Indigo) on Mac, eclipse crashes after a few seconds
This used to work fine on my current setup.
Running the app straight (debug mode) on my phone works fine.
The error from the console is:
Invalid memory access of location 0x10073f113 rip=0x101f656f7
Bus error: 10
I'm using Mac OS X 10.7.4 on a ~2010 MacBook Pro, with the following java:
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
I'm using ADT 20.
I've tried reinstalling Eclipse and the Android SDK, and re-downloading ADT.
The Eclipse error view doesn't show anything
Any ideas of different methods I can try, or other ways to investigate what's going wrong?
Cheers
Update: For anyone coming along post-2014, you should be using Android Studio, which doesn't have this problem.
Disable Project/Build Automatically when you are exporting
I think is a problem of Eclipse unable to detect the Android command is still working or something similar.
Of course there is ever the option of APK generation using Ant outside Eclipse you can generate an Ant build.xml from your Eclipse project more info in official Android docs
Disable Project->Build Automatically. I've noted that this works for me.
Disable project/build Automatically before export the apk.
This seem to be problem with your JVM. Can you update your java and check again. Also check this link
project/ clean worked for me. I think it could be related to the building of the project, as other users have posted.
The problem has gone until I have update ADT and Eclipse. I don't know which one solve the issue.
Now it's working smoothly for severeal signed export, with:
ADT Version: 22.2.1.v201309180102-833290
Eclipse Juno Service Release 2 Build id: 20130225-0426
Gentoo Linux running Java 1.7.0_45-b18.
UPDATE: Few exports after, I still get crashes from time to time, but no very frequently.
may be you should try to add execute authority . you can try something like this
first close auto-build
cd /home/your name/android-dev/sdk/tools/
sudo chmod +x zipalign
done and good luck to you
I used the disable Build Automatically for months now, until I realized that AWS plugins were slowing down the entire launch process. I uninstalled all AWS plugins from Help->InstallationDetails and everything now works perfectly as before. I do not need to disable Build Automatically any more.

How to diagnose "Error executing aapt" error in Eclipse?

I'm ready to tear my hair out because I can't get Eclipse unstuck from a state where it thinks it can't find aapt:
Error executing aapt. Please check aapt is present at /usr/local/android-sdk-linux_x86/platform-tools/aapt
I've found a bunch of posts on this subject, which suggest deleting the error in the Eclipse UI, deleting R.java, rebuilding the project, restarting Eclipse, etc. These things help temporarily, but as soon as I edit an XML file, Eclipse gets borked again. It's getting really annoying to rebuild all my source and restart Eclipse every time I change an XML file.
aapt is clearly there:
$ ls -l /usr/local/android-sdk-linux_x86/platform-tools/aapt
-rwxr-xr-x 1 boris boris 3764858 2011-07-28 11:50 /usr/local/android-sdk-linux_x86/platform-tools/aapt
Is there a way to know exactly what the error is that's occurring? I tried looking in the Eclipse console output and in .metadata/.log in my project and didn't see anything related.
Hit this again today, and discovered that verbose output from aapt doesn't help. It just spits out the aapt command to the console and fails without an error.
I think I've finally gotten to the bottom of what's going wrong. I believe that aapt is failing due to insufficient memory. My Eclipse process was using 1.2GB of memory. When Eclipse runs aapt, it forks the process which, from what I understand, allocates another 1.2GB just for running aapt.
I looked at my process list, and saw that Firefox was using almost 400MB of memory. I killed Firefox, and then aapt started working. Crazy.
Finally found the answer to my question here:
http://groups.google.com/group/android-developers/browse_thread/thread/bad9d488d2068260
Turns out that you can see the aapt command and output by setting "Build output" to "Verbose" in Preferences/Android/Build. Weird that they don't spit out the output when an error occurs.
In my case (fresh Eclipse installation, new project generated with wizard, errors like "Couldn't resolve R to variable") the problem turned out to be with absense of trailing slash in path to Android SDK at Preferences->Android.
Hint (suggested by Eclipse on Ubuntu): On 64-bit systems, make sure the 32-bit libraries are installed: sudo apt-get install ia32-libs
That has solved my problem !
I had this because of a misdeclared ID in one of the resources files. I'm using Android Studio (but not gradle), and I had in a style declaration a reference to an #+id/... which isn't allowed, apparently. I had to declare the ID in another values xml files as <item type="id" name="..." />.
This error can be caused by an invalid drawable id, such as
android:icon="#drawable/ic_action_search_whatever"
If there is no drawable called ic_action_search_whatever aapt will die. Simple error, but not an easy one to debug!
In my case, the "Android SDK Build Tools" (version 20.0) was broken somehow. So I updated the tool to the latest one(21.1) using the "Android SDK Manager" & voila - it got OK :).
Aapt is a 32bit application. I am running ubuntu 64bit. I needed some additional libraries.
To get aapt working (this fixed my issues with the avd as well) just run these two commands:
sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1
Enjoy
I actually noticed that I had converted my jpg file to png file that's why the aapt error was coming.

Categories

Resources