37

I want to reduce Android Studio project size to save it for after use

In MS Visual Studio, we can delete *.ipch, *.sdf and Debug files to reduce the project size

I see app/build/intermediates folder is really large, can I delete this folder?

thepurpleowl
  • 147
  • 4
  • 15

6 Answers6

51

Yes, you can safely delete the intermediates folder. You can even delete the whole build folder that contains intermediates. The build folder and it's contents will be re-generated the next time you run/build your project though.

fweigl
  • 21,278
  • 20
  • 114
  • 205
11

In Android Studio, go to the Terminal window. If you did not go to a different directory since you opened the IDE, you should find yourself on the top level of your project folder (something like ../Android Studio/projectname). There you simply type

./gradlew clean

That's it. I just reduced my project folder size from 589 MB to 21 MB.

kalabalik
  • 3,792
  • 2
  • 21
  • 50
5

The file .gitignore containted in the project created by AndroidStudio lists all files / patterns not to be stored in the git repository, i.e. those files that are not required for building the project. Therefore, it should be safe to remove all files / directories matching the patterns listed in the .gitignore file.

In my projects it lists:

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Meixner
  • 615
  • 5
  • 8
  • 1
    Makes TOTAL sense. It might not guarantee total cleanup, but rather maximum safe cleanup using filters. While not using automated routines might sound as a drawback, it is reassuring because user has total control of all performed acts. Will benchmark against other proposèd solutions. – tony gil Feb 25 '18 at 10:20
1

Please find the batch file I use to do that. Set the batch under the root of your project directories. Hoping it helps.

@rem  ##########################################################################
@rem
@rem  Export an ANDROID STUDIO application 
@rem
@rem  ##########################################################################


echo off
CLS
echo _________________________________________
echo ANDROID-STUDIO files sources export
echo _________________________________________
echo 
echo If directory name includes space
echo - Surround name with quotes 
echo _________________________________________
set /p dirname= Dir name to export :
if %dirname% == "" goto ERROR
set str=%dirname%
mkdir c:\EXPORT\%str%
pause
xcopy %dirname% c:\EXPORT\%str% /s
del c:\EXPORT\%str%\*.iml
del c:\EXPORT\%str%\app\*.apk
rmdir c:\EXPORT\%str%\.gradle /s /q 
rmdir c:\EXPORT\%str%\.idea /s /q 
rmdir c:\EXPORT\%str%\build /s /q 
erase c:\EXPORT\%str%\app\build /f /s /q
rmdir c:\EXPORT\%str%\app\build /s /q 
pause
goto END
:ERROR
echo Cannot create, check the directory root
goto OUT
:END
CLS
echo _________________________________________
echo  ANDROID-STUDIO EXPORT
echo _________________________________________
echo Export ended, check c:\EXPORT
:OUT
pause
Kaunis
  • 11
  • 3
  • I used your code, at first I got the error "“Please select Android SDK" when executing the new exported code in the emulator but I solve it with this answer https://stackoverflow.com/a/49568712/1363087 By the way, the app changed from 400Mb to 20Mb. Great to store in DropBox. After rebuilding it went up to 80Mb. Thanks – Ton Apr 12 '18 at 16:39
  • By the way, it also makes you select the Keys to build the apks. Is there an option to not delete something so these 2 issues are gone? I don't mind if the exported file is a bit larger. I need to use your batch file many times, but I would prefer to not have to do those 2 issues each time. Thanks – Ton Apr 12 '18 at 18:08
0

Mac & Linux users:

In terminal type ./gradlew clean in the root of your android project.

Windows users:

In cmd paste gradlew clean in the root of your android project.

Community
  • 1
  • 1
Aftab Alam
  • 1,969
  • 17
  • 17
0

In Android Studio:

Click on Graddle >> app >> build >> and double click on "clean"

clean gradlew

Dimitar
  • 659
  • 7
  • 6