/AndroidGradle

Basic Gradle setup for an Android project with a separate Robolectric test project

Primary LanguageGroovy

Building an existing project

These are instructions for building an existing Android project using gradle.
If you want to create a new Android project using gradle, please proceed to Creating a new project

Setting the Android SDK dir

  1. cd into the AndroidProject folder
  2. create a file called local.properties
  3. in the file, enter your local android sdk dir: sdk.dir=/path/to/sdk/dir

Building from gradle

  1. cd to the root folder
  2. type gradle androidPackage to do a complete build (including tests)
  3. type gradle androidInstall to install the application in a device or a running emulator
  4. type gradle tasks to see a list of all gradle tasks

Importing into Eclipse

  1. cd to the root folder
  2. type gradle eclipse
  3. start Eclipse
  4. select File - Import - Existing Projects into Workspace
  5. select the root folder containing the AndroidProject and the AndroidProjectTest projects
  6. right click on the AndroidProject
  7. select Android Tools - Fix Project Properties

Setting up Eclipse test configuration

  1. in the project explorer, select the AndroidProjectTest project
  2. select Run - Run Configurations...
  3. select JUnit and click the yellow + button
  4. select Test Runner - JUnit 4
  5. go the the tab 'Arguments'
  6. select Working directory - Other
  7. select Workspace... - AndroidProject and click OK
  8. click Multiple launchers available - Select one...
  9. choose the Eclipse JUnit Launcher (NOT the Android JUnit Test Launcher)

Creating a new project

These are instructions for using the gradle build files from this project in a new Android project.

  1. Copy the following folder structure from this project:

    • .gitignore
    • build.gradle
    • README.md
    • settings.gradle
    • AndroidProject
    • AndroidProject/build.gradle
    • AndroidProjectTest
    • AndroidProjectTest/build.gradle
  2. Create a new Android project in the AndroidProject folder. You can use Eclipse for this.

    • Make sure the target folder for the new Eclipse project is the AndroidProject folder.
    • Do NOT create an android Test Project.
  3. Follow the steps in Setting the Android SDK dir as described above

  4. Go to the root folder (containing README.md) and type gradle :_AndroidProjectTest_:eclipse

  5. In Eclipse: import the generated existing project into the workspace

  6. Follow the steps in Setting up Eclipse test configuration as described above

Attention

  • You can change the project names AndroidProject and AndroidProjectTest into XXX and _XXX_Test.
  • It is possible to use AndroidProject/build.gradle without the test project.
  • Make sure you do NOT check in files specified in .gitignore in version control. This will cause problems.