Android Project Converter

This is a tool to help convert Android projects from their "old-style" project structure to the project structure that fits Gradle builds and Android Studio.

View project onGitHub

AndroidProjectConverter v1.3.0

Overview

This is a command line tool to help convert Android projects from their "old-style" project structure to the project structure that fits Gradle builds and Android Studio. It is written in Java so it can easily be run in any environment. When executed this program will create a backup of the original project and create a new project that can be used with Gradle and Android Studio.

Usage

  1. Download the jar from here.
  2. Open a command prompt window and execute as follows:
java -jar apc.jar "C:/Path/to/original/project" "C:/Path/to/converted/project" "Name"

For example: The following command would convert a project called MyCoolApp.

java -jar apc.jar "C:/android/MyCoolApp" "C:/android/MyCoolAppProject" MyCoolApp

All jars that are in the project's `libs` directory will automatically be copied and added to the module's `build.gradle` file as `compile` dependencies.

Usage With Test Projects

This program can convert not only an Android project but also an Android Test Project simultaneously. A path to the test project needs to be specified as an extra argument. For example:

java -jar apc.jar "C:/android/MyCoolApp" "C:/android/MyCoolAppProject" MyCoolApp "C:/android/MyCoolAppTest"

All jars that are in the test project's `libs` directory will automatically be copied and added to the module's `build.gradle` file as `instrumentTestCompile` dependencies.

How It Works

First it is worth noting that a Gradle project is structured like a maven project; a project may contain modules. Android Studio defaults to creating a project with one module (which is the Android app). This utility follows that structure. The parent project and each of its modules have a build.gradle file. This specifies how the project and modules are built.

The Gradle Wrapper is a very important piece that should be attached to any gradle project. The wrapper is all inclusive and allows for gradle execution anywhere without having to install anything for gradle. USE IT! It can passed around with the project through source control and it makes all of our lives just a bit easier.

What this tool does (high level):

  • This tool will first copy the project that should be converted as a backup.
  • Creates a gradle project shell. The shell includes a project and a module. This step copies all of the default files (gradlew and build.gradle files) to the right places in the shell.
  • The project is copied
    • The contents of the src directory are copied to <module>/src/main/java
    • The contents of the libs directory are copied to <module>/libs and all of the dependencies are added to the module's build.gradle file.
    • Any other files or folders (exclusive of build or auto-generated files and folders) are copied from the root of the source project to src/main/ in the gradle project.
  • The test project is copied (if specified)
    • The contents of the src directory are copied to <module>/src/instrumentTest/java
    • The contents of the libs directory are copied to <module>/libs and all of the dependencies are added to the module's build.gradle file as test project dependencies.
    • The contents of the res directory are copied to <module>/instrumentTest/res/

If your project uses any libraries see below for suggestions on how to use them.

Contributing

This is a maven project, built with Maven 2.2.1 Once the source is downloaded, execute the following from the root directory:

mvn clean verify

This will run all tests and pull all dependencies required.

How does this work with a project using Android Libraries?

To reference a library in Andriod Studio, both the library and the project must be imported into Android Studio. Referencing `.aar` files isn't yet supported. The alternative is to get the .aar file from a maven repository. Many popular libraries are already hosted on maven central, however they can easily be uploaded to a local maven repository. I suggest Sonatype Nexus.

Change Log

v1.3.0

Added the ability to check for updates.

v1.2.0

Added the ability to copy an Android Test Project simultaneously with an Android Project.

v1.1.0

Added support to modify Module build.gradle file with all dependencies in a lib(s) directory.

v1.0.0

Initial Release

Roadmap

  1. Work with Android Library Projects.
  2. Provide an option to use dependencies from maven central instead of local libs if available.