Atul
Atul

Reputation: 4320

Android Studio: Need to know which folders/files to backup

I have to take backup of Android project. But the entire folder structure size is very big (goes upto few hundreds of MBs) for periodical backups. Basically I want to take backup of only source and configuration files (so that I should be able to build project successfully just with backup). I don't care generated and intermediate files.

But when I've look at folder structure, it looks too confusing and cannot make which folders/files I should backup and which should discard (Yes, I can find out my own written source files, but which are config and other files needed by Android Studio?)

enter image description here

Can someone please guide?

Thanks!

Upvotes: 10

Views: 4187

Answers (5)

Lins Louis
Lins Louis

Reputation: 2643

Actually, it is very simple in the android studio. Only you have to do is just

File ->Export to Zip File This will create a zip file of your project. This Zip file will only contain the files that are necessary, to import the project back into Android studio again.

Edit: From the new Android Studio Version Export to Zip flow changed(My Version: Android studio 4.1, Running in Mac Os Catalina). Now it is File->Manage IDE Settings ->Export to Zip FIle.

Upvotes: 7

navid
navid

Reputation: 1398

I usually need to make copies of my android studio projects. The size of the copy is mostly affected by generated files which aren't vital for a successful build of the project copy, but if not present you need to wait for them to be generated again.

Directories I ignore when copying:

  • root
    • .gradle
    • .idea
    • build
    • app (or any other module)
      • build

Also you may have some debug/release APK files that you don't want to keep in the copy.

Windows xcopy can make your life easier due to its exclude option (for APK files add '.apk'). Furthermore you may like to check out this windows tool as you can reuse your exclude configurations: https://sourceforge.net/projects/xcopygui

Upvotes: 0

shizhen
shizhen

Reputation: 12583

Basically I want to take backup of only source and configuration files (so that I should be able to build project successfully just with backup). I don't care generated and intermediate files.

For a reproducible backup, only backing up the the src and build.gradle is not sufficient. Because if you want to have a consistent build for your project, you need to have the same source code and configurations, for example, the top level build.gradle as well as the app level build.gradle. So, I would like to recommend below steps for an Android Studio project to have a really clean status before doing backup.

  1. Close your android studio, this is to avoid the IDE automatically trigger the build to generate the intermediate files.

  2. Open command line and cd to your project root directory, i.e. <path>/FusedLocationAPISample for your case.

  3. Run $ rm -rf .gradle .idea build app/build on linux or macOS, or run rd /s /q .gradle .idea build app/build on Windows. This command is to delete the gradle and Intellj intermediate files as well as the build intermediate files.

  4. All the other files, e.g. the gradle-wrapper.properties, settings.gradle, gradle.properties, etc, HAVE TO be kept there if you want to reproduce a consistent build next time. This is because the project setting and gradle version and properties are important for a consistent build.

Then the last step is to use your preferred way to back up your project, e.g. using ZIP and backup to a spared drive.

But, I would like to suggest using Github, Bitbucket (or some other SCM tools) to manage your code As those SCM tools are much intelligent and easier to use, isn't it?

Upvotes: 1

T D Nguyen
T D Nguyen

Reputation: 7603

You backup whatever is important. For each project or library, do backup these:

  1. src folder (contains source code, resource files)
  2. build.gradle file (contains info about dependencies, libs)

Do not need to backup:

  1. build folder
  2. gen folder
  3. .gradle folder

Note: Clean Project sometimes does not remove generated files.

Upvotes: 4

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

Use Build -> Clean Project to clean it and remove all generated files. Then you have the list of files to backup.

Upvotes: -1

Related Questions