Duplicating Android App Eclipse project

When developing an online Android app, it is easy to put in a switch whether it should run in live/test mode. After the initial live release however, there might be a need to install both versions on a single device. To create an identical Eclipse project with a different package name manually, you need to do a few steps:

  • Copy the project to a different folder.
  • Change the Eclipse project name in the .project file to be able to import it into the same workspace.
  • Load the project into eclipse.
  • Use refactoring to rename your application package.
  • Change all other references to your package, especially in the Android manifest.
  • Change app launcher know, so you’ll know which is which.

This simple windows batch file below does exactly that automatically. You no longer have to manually re-create or synchronise all changes into your test project, just run the script and build.

It uses the open source Find And Replace Text tool, or FART for short. It is a small program with no dependencies.

Don’t forget to change the variables on top and to add other things that may be necessary for your particular project. The example below assumes a standard Eclipse Android project, with the app_name variable specified in strings.xml.

@echo off

rem ===========================================================================

rem Change these variables to match your project. The orig project will be
rem copied to the test project.

rem _folder  - Project folder relative to current folder
rem _package - Android app package
rem _project - Eclipse project name as found in .project
rem _appname - App launcher name

set orig_folder=example
set orig_package=com.example.app
set orig_project=Example App
set orig_appname=Example

set test_folder=example-test
set test_package=com.example.apptest
set test_project=Example App Test
set test_appname=Example TEST

rem ===========================================================================

rem Delete test folder if already exists
if exist "%test_folder%" rmdir /q /s "%test_folder%"

rem Delete bin and gen folders from original
rem Gets rid of lots of files that don't need to be processed
if exist "%orig_folder%\bin" rmdir /q /s "%orig_folder%\bin"
if exist "%orig_folder%\gen" rmdir /q /s "%orig_folder%\gen"

echo Copying project files...
xcopy /q /e /i "%orig_folder%" "%test_folder%"

echo Renaming project and package...
fart -q -r -- "%test_folder%\*.*" "%orig_package%" "%test_package%"
fart -q -- "%test_folder%\.project" "<name>%orig_project%</name>" "<name>%test_project%</name>"
fart -q -- "%test_folder%\res\values\strings.xml" "<string name=\"app_name\">%orig_appname%</string>" "<string name=\"app_name\">%test_appname%</string>"
move /y "%test_folder%\src\%orig_package:.=\%" "%test_folder%\src\%test_package:.=\%"
Share Button
Tagged with: , , ,

Leave a Reply