Android studio location of caches/generated sources - android-studio

I have switched to using Android Studio 3.1 RC2. I have detected that when I switch branches, I am running across generated sources from other branch. They still show up even if I do Build -> Clean Project. Or manually delete build folders in all my modules as well as top level build folder.
Only way to rectify this is delete .gradle folder in my project directory and my $HOME/.gradle , this is very time consuming.
Where does Android Studio keep its caches of generated files. I have tried Android Studio's clean "Invalidate Caches/Restart" without much help.

You can use
./gradlew cleanBuildCache
to clean up all caches under HOME/.gradle
See: https://developer.android.com/studio/build/build-cache.html

Related

How to fix "synce failed"

My android studio worked fine but now I always have this message when I start it:
C:\Users\GERA.gradle\caches\4.6\file-changes\last-build.bin (Access is denied)
Also my files tree looks diferent now and Java files are not blue anymore.
This is a Android studio level problem, not only one project.
How to fix that?
Go to File-> Invalidate caches / Restart
remove .gradle folder
Restart Android Studio
Gradle build succeed
Rebuild project

Why is Android studio not automatically cleaning my project

I recently renamed my project by closing Android Studio, renaming the root project directory then opening A.S again.
A.S names the project using the new directory name, then I open it. A new .iml file is created with the new name. I deleted the old one and cleaned the project.
Everything went fine but now when I build it just deploys the app instead of cleaning it first. I have to manually clean it and it's annoying.
Is there a setting that might have gotten messed up?
Platform Details: Android Studio 3.0.1, Windows 10
Ok. So, apparently if you add flavors to your project then you have to manually clean the project otherwise when you build, Android Studio will launch the previous APK.

Android Studio "cannot resolve symbol" but project compiles and works

The project compiles fine. However, Android studio 3.0.1 shows reference to one particular library in red and displays "cannot resolve symbol". Even single stepping into that library module doesn't work.
I already tried various options like 1) Invalidate cache/restart 2) deleted build directory 3) clean and rebuild but nothing seems to be working.
Interestingly, when Android Studio is rebuilding indexes after invalidate/restart, it momentarily shows that library references in while but then again in red.
I tried Invalidate cache/restart or clean Project -> rebuild project. These didn't work for me.
The final solution was open Project window on the left side of IDE, under Project mode, delete .gradle and .idea folder, then sync, it works.
Following has resolved this for me.
remove library from gradle cache (in case of linux, it's in ~/.gradle/caches).
remove library dependency from the build.gradle and sync
restart (maybe invalidate cache)
add library dependency to build.gradle and sync
clean and rebuild
This is happen to me when I move my project to other pc or open the project with other pc and with different SDK folder location. Solution: close project, delete folder .gradle and folder .idea inside project folder then open your project to sync gradle.
In my case changing the Gradle version worked.
In gradle-wrapper.properties
changing
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
and in build.gradle (project level)
changing
classpath 'com.android.tools.build:gradle:3.3.0'
to
classpath 'com.android.tools.build:gradle:3.2.1'
Invalidate cache/restart didn't work for me.
Simple and working solution:
1: Remove all dependencies from App level Gradle and Sync.
2: Re-add all these dependencies and Sync.
It will work fine.
This has happened to me a couple of times, there are a few ways you can resolve this problem;
Sync project files with gradle in the File toolbar
Use the Invalidate/Restart option in the File toolbar to invalidate the caches.
Delete the .idea folder and restart Android Studio
Firsty try to Clean and rebuild project from Build -> Clean project & then Build -> Rebuild project.
If that doesn't work Invalidate Caches/Restart always works for me. Do it from File -> invalidate Caches/Restart
Then click on invalidate and restart
Hopefully this helps.
For me problem was that AS suggested I upgrade gradle version, (from 3.5 to 4.4), and then it started doing it.
Solution was to delete the 3.5 folder from .gradle in project
None of the answers worked for me
Fixed it by:
Removing & adding all java files via Project window on the left side of Android Studio
Commenting/un-commenting & syncing libraries in the gradle file in small groups.
And cleaning all caches before that (as part of other fixes here).
I've tried Invalidate Caches/Restart..., tried manually delete .idea and .build folders and it didn't work for my case.
I using VCS (git) and I just commit my changes, removed the whole project, and Checkout from Version Control. It fixed this problem.
Android Studio 3.6.3
I Tried the following in order to resolve the issue:
Invalidated Caches/Restart
deleting .idea, .gredle under project and build under app
done clean project and rebuild project
deleted the caches in the installed path
Eg. {installed path}.AndroidStudio4.0\system\caches
upgraded the studio to latest version
[I have installed as suggested by windows, so its installed same path. I might have tried new path.]
Non of these tries helped to resolved this issue. Finaly I have tried these two steps:
commented dataBinding.enabled true from build.gredle of your app as its obsolete and replaced with buildFeatures{dataBinding true}.
Deleted the content of the log, tmp and caches folder from the installed path manually. Eg. {installed path}.AndroidStudio4.0\system\caches, {installed path}.AndroidStudio4.0\system\log, {installed path}.AndroidStudio4.0\system\log
Restarted the android studio
Now all reference for the Binding and other classes were restored.
I ran into this problem after upgrading Android Plug In Version from 3.54 to 7.2.1 and Gradle version 5.41 to 7.3.3 . Reverting back to the earlier versions fixed the problem. Simply deleting the 5.41 folder in .gradle as suggested in another answer above did not work.
Update
classpath 'com.android.tools.build:gradle:3.X.X'
to the last version worked for me.
Tried all of the above but nothing worked.
Got Solution by:
1. Updating Android studio to latest version
2. Updating the Gradle version to latest one

Disable Instant Run for project

I have a project that does not build if you try to build it with Instant Run enabled. That's why I would like to disable Instant Run for that project.
Can I do that in a way that can be committed to the repository?
if you want to disable instant-run ONLY for the project that is not compatible (i.e the one with SugarORM lib)
on root of your projct open gradle-->gradle-wrapper.properties then change the value
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
and
on your project build.gradle change the value
classpath 'com.android.tools.build:gradle:2.2.3'
If you want to disable instant-run for all project (Across Android Studio) see this
It's not possible to turn off Instant Run for a Project only till now available stable version of Android Studio 2.3
But to build the Project properly with Instant run enabled and it will not affect the project try to remove the .idea folder and .gradle folder, then click Sync Project with Gradle Files, when the process finished, try to run app.
Hope this solution works for you.

How to project clean in Android Studio?

I am new in Android Studio so I face some problem with it. I am looking for a way how to project clean.
In Eclipse I would do Project -> Clean -> OK but I don't know how it is done with Android Studio.
You can clean your project doing this
Build > Clean Project or Build > Rebuild Project
Also you can do the gradlew clean
As #Kellogs commented :
Manually delete the [project]/.gradle as hidden folder as that one is the main culprit for large cleaned projects sizes.
Cleaning an android project is quite simple just follow these steps
1. Click on Gradle pane,found in the top-right corner of Android Studio
2. Click on your project,then Tasks -> build ->clean
Step 1
Step 2
Note Never clean your project using the Build -> Clean Project.Instead of cleaning your project it will increase the size of it.
Update clean has been replaced by cleanBuildCache in the recent versions of Android Studio.

Resources