Hide
Python

Creating and Configuring Your Project

To start off the tutorial, you need to create a new project and add the client library for the backend API. Then you need to configure the project for all the required dependencies, as we'll describe below.

Creating an Android Endpoints Project

To create a new project:

  1. Start Android Studio. (In Linux, you do this by invoking studio.sh.)
  2. Click Start a new Android Studio project.
  3. Fill out the New Project form:
    1. Supply Hello Endpoints as the Application name.
    2. Supply supply HelloEndpoints as the Module name.
    3. Supply supply com.google.devrel.samples.helloendpoints as the Package name.
    4. Select API 11: Android 2.3 for the Minimum required SDK, select API 19: for the Target SDK, and select API 19 for Compile with. You don't have to use these API levels, but these are the ones we are using for this tutorial.
    5. Leave all of the other settings as is, accepting the defaults.
  4. Click Next.
  5. Click Next to accept the defaults when prompted to supply an image file and other settings.
  6. Accept the default Blank Activity by clicking Next.
  7. Accept the default activity name MainActivity by clicking Finish. Note that the HelloEndpoints project appears in the left panel, with the project subdirectories located under the project name.
  8. Open a terminal window and change directory to HelloEndpoints/HelloEndpoints and create a subdirectory named libs.
  9. Locate the backend API client library Jar, which you generated following the instructions in setup.
  10. Copy the backend client library Jar to the project's /libs directory:

    location of libs directory

  11. Return to the HelloWorld project in Android Studio, and select the library you just added, right-click, then select Add As Library to your project.

This completes the project creation, so let's proceed to configuring the your project via the build.gradle file.

Configuring the Project

In Android Studio, your project uses the build.gradle file for dependencies and other settings. This file is located at HellowWorldProject/HelloWorld/src/build.gradle:

the_libs_dir

To configure build.gradle:

  1. Locate HelloWorldProject/HelloWorld/src/build.gradle in the Android Studio left pane, and double-click build.gradle to open it.

  2. Replace all of the contents with the following code:

    apply plugin: 'android'
    
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"
    
        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 19
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile 'com.android.support:appcompat-v7:+'
        compile 'com.android.support:support-v4:19.0.+'
    
        // BEGIN Google APIs
    
        // Play Services will validate the application prior to allowing OAuth2 access.
        compile(group: 'com.google.android.gms', name: 'play-services', version: '4.2.+')
    
        // The following lines implement maven imports as defined at:
        // https://code.google.com/p/google-api-java-client/wiki/Setup
    
        // Add the Google API client library.
        compile(group: 'com.google.api-client', name: 'google-api-client', version: '1.17.0-rc') {
            // Exclude artifacts that the Android SDK/Runtime provides.
            exclude(group: 'xpp3', module: 'xpp3')
            exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
            exclude(group: 'junit', module: 'junit')
            exclude(group: 'com.google.android', module: 'android')
        }
    
        // Add the Android extensions for the Google API client library.
        // This will automatically include play services as long as you have download that library
        // from the Android SDK manager.
        // Add the Android extensions for the Google API client library.
        compile(group: 'com.google.api-client', name: 'google-api-client-android',
                version: '1.17.0-rc') {
            // Exclude play services, since we're not using this yet.
            exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
        }
    
        // END Google APIs
    
        // The following client libraries make HTTP/JSON on Android easier.
    
        // Android extensions for Google HTTP Client.
        compile(group: 'com.google.http-client', name: 'google-http-client-android',
                version: '1.17.0-rc') {
            exclude(group: 'com.google.android', module: 'android')
        }
    
        // This is used by the Google HTTP client library.
        compile(group: 'com.google.guava', name: 'guava', version: '14.0.+')
    
        compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    }
    

    In this configuration, notice, under dependencies, the line:

    compile 'com.android.support:support-v4:19.0.+
    

    Using v4 support lets you target API 8 and above, providing more APIs than v7.

  3. Click File > Save All and then exit Android Studio and restart it.

  4. Click Build > Rebuild Project.

With setup and configuration complete, you are now ready to start create the UI and add other code for a simple Android app.

Next

When you are finished with these tasks, continue on to Creating a Simple Android App.