Android Studio: What to Exclude While Importing a Project into Subversion?

If you put an Android Studio project under version control with Subversion, you will have to exclude some files from version control. Otherwise you will have local settings in your repository which will not work on other workstations. See what you have to add to Subversion’s ignore list.

First of all you will have to create your Subversion repository. svnadmin create will be your friend here.  We will not cover creating of repositories in this post. In the following text we will assume that the newly created repository is available via HTTPS from a webserver.

If you need further assistance in creating a repository and/or making it available via https you will find it in the official Subversion documentation.

Check out

Let’s assume that we have created our project in Android Studio already and it’s located in ~/AndroidStudioProjects/foo (Linux or Mac OS X) and ${ENV:USERPROFILE}\AndroidStudioProjects\foo (Windows) respectively. It’s an app project which resides in the sub directory app.

Note: If you create additional modules in your project you will have to process these directories exactly the same as the app directory!

Our repository for this project foo is available under and provides already the standard folder structure:

+-- trunk
+-- tags
+-- branches

First we open a terminal window (Linux or Mac OS X) or a PowerShell window (Windows).  Now we change the current working directory to our projects path:

Linux or Mac OS X:

cd ~/AndroidStudioProjects/foo


cd ${ENV:USERPROFILE}\AndroidStudioProjects\foo

In the next step we check out the trunk tree of our repository. Note that at this moment our trunk tree is still empty! The already existing files and directory in our project’s directory won’t be affected by this check out step.

svn co .

At this point we have made a working copy out of our project’s path. Before we add the content of our project to Subversion we need to exclude the local settings and build results.

Prepare Project’s Root Directory

Now we add the following files and directories respectively to Subversion’s ignore list:

  • .gradle
  • build

This is done by the following command. Note here that this command is a multiline command which works in the same way in Windows’ PowerShell as in the Unix shell of Linux and Mac OS X. In PowerShell you only need to commit this command by an additional empty(!!) line after the command.

svn ps svn:ignore '.gradle
build' .

svn will print this output on successful execution:

property 'svn:ignore' set on '.'

Preparing the Directories app and .idea

Next we add the directories app and .idea to Subversion so that we can change their ignore lists, too. Here we have to make sure that we add only the directories and not their contents! This is assured by the command switch --depth=empty which switches off recursive processing of directories.

svn add --depth=empty app .idea

Note: If your project contains more modules you will have to add these directories to this command, too! The same applies to the following command in which “app” also appears.  

Now we exclude the whole directory build in app from version control:

svn ps svn:ignore build app

We also exclude the directory libraries as well as the files gradle.xml and workspace.xml from .idea:

svn ps svn:ignore 'libraries
workspace.xml' .idea

Adding the Rest of the Project

Last but not least we can add the rest of our project to subversion. Here we have to determine the files which should be added based upon our excludes. It is necessary to process the files which are given by the output of svn st. If we were doing a simple recursive svn add here the files from the exclude lists would be added, too. So we need a bit sophisticated command.

On Linux and OS X we perform a bit magic with awk and xargs:

svn st | awk '$1 == "?" { print $2 }' | xargs svn add

On Windows the same effect will have this PowerShell command:

svn st | %{ $a = $_.trim() -split ' +',0,"regexmatch"; if($a[0] -eq '?') { Invoke-Expression ("svn add " + $a[1]) } }

Commit the Changes

Our working copy is prepared with all necessary files added. Our last step is to commit the changes to our repository:

svn ci -m 'Initial import'

The log message will be 'Initial import' here. Change it if you prefer another text for your initial import.

This entry was posted in Android, Android Studio, Subversion, Version control and tagged , . Bookmark the permalink.

2 Responses to Android Studio: What to Exclude While Importing a Project into Subversion?

  1. Milen Marinov says:

    This is an EXCELLENT guide! I was searching on how to properly import my project in svn and was getting frustrated until I found this.

    THANK YOU so much!

  2. colo says:

    Perfect manual, thanx.

Leave a Reply

Your email address will not be published. Required fields are marked *