iZBasit
iZBasit

Reputation: 1313

Unable to clean project in Android Studio

OS version: Ubuntu 14.04 LTE 64 Bit

Java JRE/JDK version: Oracle JDK 1.8.0_11

Project directory is on a NTFS based drive.

Whenever I try to clean my project I get something like below.

:app:clean FAILED Error:Execution failed for task ':app:clean'.

Unable to delete file: /media/DriveA/AndroidStudioWorkspace/DNA/app/build/intermediates/classes/debug/.../mechandising/MerchandizingActivity$3.class

When I try to delete the build folder manually I get the following error.

Error when getting information for file '/media/DriveA/AndroidStudioWorkspace/DNA/app/build/intermediates/pre-dexed': Input/output error

I am unable to figure out whether its a Linux problem or a Studio problem. I don't face such a problem in Eclipse (Same Drive) so I am just considering it to be something wrong with my studio.

Any Suggestions??

Upvotes: 41

Views: 85032

Answers (22)

Please note that the solution that I am noting below is specifically for people that are working with the Android configuration in a React Native project.

This is an older issue, but can come up in certain scenarios even still. The problem came up for me when I needed to update the compileSdkVersion in my React Native project, because google recently required it to be updated in order to remain active on the app store. After I updated the compile sdk version though, gradle stopped working completely. gradlew clean wouldn't work, and my react-native app wouldn't build no matter what I tried. It got stuck on the initializing step. So I decided to take the plunge and decided to try to refresh the android project from a later version of React Native. Here is how I got it working in my case. I'm hoping this will help some poor soul out there that couldn't find the root cause.

The solution was to get the android gradle plugin version, and the gradle version in sync again.

I started by backing up my entire project in a git branch, and I committed and pushed the changes (of course.)

Then in a terminal I went to a fresh folder with nothing in it and started a new react native project. I copied the entire Android folder from the new project over the top of the Android folder in my project (but I didn't delete the old Android folder first, ... instead I copied it over the top of the Android folder in my project so that it would only replace the main project files, but it kept the files that were different). Then I went over the git diff changes very carefully. Surprisingly in my case there weren't many conflicts that I had to fix, but I had to be careful about how I handled some of the differences. Then I deleted my node_modules folder, and my .gradle folder and did an npm install.

One big difference was that when I first started my React Native project, Kotlin wasn't a dependency I think. I noticed that Android in React Native included Kotlin in some of the build dependencies in newer versions of React Native, but not in older versions (I think).

After that it started compiling again.

Upvotes: 0

Varsha Pandit
Varsha Pandit

Reputation: 1

I solved it by Upgrading gradle version in build.gradle(project)

Upvotes: 0

Supriya
Supriya

Reputation: 581

1) first run cordova clean cammand

ionic cordova clean

2)After that run build command

ionic cordova build android

Upvotes: 0

Saqib
Saqib

Reputation: 43

Running android studio as administrator in windows worked for me. :)

Upvotes: 0

Abdelsalam Hamdi
Abdelsalam Hamdi

Reputation: 515

1) Go To File > Settings > Build, Execution, Deployment > Instant Run > Uncheck this Check box (Enable Instant Run to hot swap code).

2) Restart your android studio

Upvotes: 0

Dlong
Dlong

Reputation: 79

I came to this thread because I was having issues with my /release/app.aab getting locked. This prevented me from completing a project clean and generating a signed bundle. My work around was to restart my computer to get permissions back until I solved the issue.

It turns out that Git was locking the app.aab, and all I had to do was add "/release" to my /app/.gitignore.

Hope this helps someone.

Upvotes: 0

ChillingVan
ChillingVan

Reputation: 141

It should be a process lock the file handle. You can try to open your task manager to kill the process. In my case, the process is one of the Java process hold by Android Studio OpenJDK. Just find it and kill it.

Upvotes: 0

sajad abbasi
sajad abbasi

Reputation: 2184

none of above answers didn't work for me, but change permistion works:

chown user:staff ../project_dir
find ../project_dir -type d -exec chmod 775 {} \;
find ../project_dir -type f -exec chmod 664 {} \;

Upvotes: 0

Febin K R
Febin K R

Reputation: 986

I had the same problem. To build the project again and again I had to delete the build folder each time. The problem for me was an anonymous program called ByteFence.exe running in my system. When I uninstalled that program my issue was solved.

Upvotes: 0

Ashley Chipman
Ashley Chipman

Reputation: 9

This fixed my problem.

Thanks to Gal's answer (https://stackoverflow.com/a/39904628/2870404).

In windows, using Windows file explorer,

right-click on the directory, click properties on the context menu that will appear, then uncheck the "Read Only" attribute. After that, click the "Apply" to apply changes.

Upvotes: 0

Saef Myth
Saef Myth

Reputation: 297

I stopped the windows defender it was locking the file because it was need to scan , and the problem resolved

Upvotes: 1

Gal Rom
Gal Rom

Reputation: 6461

On Linux this could happen if you have a locked directories that prevents Android Studio from Deleting files.

you can run the Following command on Terminal:

sudo chown -R $USER: $HOME

Then try to rebuild --> Works for me

Upvotes: 1

Happy Singh
Happy Singh

Reputation: 376

Go to

File > Settings > Build, Execution, Deployment > Instant Run > Uncheck this Check box (Enable Instant Run to hot swap code)

Thanks Have a nice coding

Upvotes: 21

Ray Lionfang
Ray Lionfang

Reputation: 687

Thanks to Gal's answer (https://stackoverflow.com/a/39904628/2870404).

In windows, using Windows file explorer,

  1. right-click on the directory,
  2. click properties on the context menu that will appear,
  3. then uncheck the "Read Only" attribute.
  4. After that, click the "Apply" to apply changes.

Upvotes: 0

tricknology
tricknology

Reputation: 1138

I'm not on Windows, but OS X. Somehow my build folder didn't have the proper permission for AS to delete the file so I did chmod -R 777 <your_directory> in the affected parent directory.. probably 777 isn't what you would want but it worked for me.

Upvotes: 0

neha thakkar
neha thakkar

Reputation: 1

I solved this issue by closing android studio -> remove android platform via cli and then -> add the android platform again -> open project in android studio.

Upvotes: 0

naslami
naslami

Reputation: 355

I had the same issue as you. I tried some of the solutions proposed on this page and it didn't work. So I used Process Explorer to find which process is locking the apk file and it was firefox. I think it keeps the file locked when I upload the apk in google play console. To make that go to "Find > Find Handle or DLL... > path-to-your-app.apk". Hope it help

Upvotes: 1

kinath_ru
kinath_ru

Reputation: 4678

I had a similar problem, when I was trying to debug my first android app. If you are running Android Studio on windows, I just restarted the Android studio and I did run Android Studio as Administrator which fixed the issue.

Upvotes: 0

JSON C11
JSON C11

Reputation: 11792

Go to your projects directory in the terminal and run gradlew clean

To run a Gradle command in your terminal/command prompt. Navigate to the root of your project and type gradlew in the terminal or gradlew.bat for the command prompt (windows users), followed by the command you would like to execute.

For a list of all possible gradle commands type gradlew tasks into your terminal.

Upvotes: 0

Vasiliy
Vasiliy

Reputation: 16228

Just ran into the same issue now - I accidentally edited one of the generated files and wanted to rebuild the app, but both clean and build failed due to some files being locked.

Luckily, I got cygwin on my Windows machine, so ls -l <file that studio complained about> revealed that these files were owned by some Administrator dude.

My first thought was that these files might had been created while Studio was running with admin privileges (I do this when I need to fetch updates from SDK manager). The idea was to try and resolve this issue by executing clean in Studio running with admin privileges, and later rebuild with normal privileges. Nope, this did not work :(

I decided to go for the brute force: sudo rm -rf app/build/* (in Cygwin this command looks a bit different: cygstart --action=runas rm -rf app/build/*). This resolved the issue and I was able to rebuild the project in Android Studio.

Upvotes: 6

You can go into the project directory and call gradle from the command-line to do a clean on the project:

gradlew clean

When you reopen the project you will need to run a gradle sync again.

Upvotes: 14

Kevin Wiggins
Kevin Wiggins

Reputation: 544

I had the same problem.

You need to go to the source file directly. Close the studio and go to the path the issue is located at and delete the folder there.

Upvotes: 38

Related Questions