可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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??
回答1:
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.
回答2:
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
回答3:
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.
回答4:
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.
回答5:
Clean project from Android Studio Terminal using this command 'gradlew clean'.
回答6:
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
回答7:
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
回答8:
I stopped the windows defender it was locking the file because it was need to scan , and the problem resolved
回答9:
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.
回答10:
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.
回答11:
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.
回答12:
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.
回答13:
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.
回答14:
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.
回答15:
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.
回答16:
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 {} \;