官术网_书友最值得收藏!

Configuring Google Play services

Google Play services include the classes required for our map application. So, it is required to set it up properly. It differs for Eclipse with the ADT plugin and Gradle-based Android Studio. Let's take a look at both separately. It will be simple.

Android Studio

Configuring Google Play services with Android Studio is very simple. You need to add a line of code to your build.gradle file, which contains the Gradle build script required to build our project. There are two build.gradle files. You must add the code to the inner app folder's build.gradle file. The following screenshot shows the structure of the project:

Android Studio

The code should be added to the second Gradle build file that contains our app module's configuration. Add the following code to the dependencies in the Gradle build file:

compile 'com.google.android.gms:play-services:7.5.0

The structure will be similar to the following code:

dependencies {
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:appcompat-v7:21.0.3'
}

The 7.5.0 in the code is the version number of Google Play services. Change the version number according to your current version. The current version can be found from the values.xml file present in the res/values directory of the Google Play services library project.

The newest version of Google Play services can be referred to from https://developers.google.com/android/guides/setup.

That's it. Now resync your project. You can sync it like this: Tools | Android | Sync Project with Gradle files.

Now, Google Play services will be integrated with your project.

Eclipse

Let's take a look at how to configure Google Play services in Eclipse with the ADT plugin. First, we need to import Google Play services into the workspace. Then, select File | Import.

The following window will appear:

Eclipse

In this window, select Android | Existing Android Code Into Workspace.

Then, select Next. In the next window, browse the sdk/extras/google/google_play_services/libproject/google-play-services_lib directory. It is given in the following image:

Eclipse

Finally, select Finish. Now google-play-services_lib will be added to your workspace. Now, let's take a look at how to configure Google Play services with our application project. First, select your project. Then, right click on | Properties.

In the Library section, select the following: Add | google-play-services_lib.

Next, select OK; google-play-services_lib will be added as a library to our application project. The following screenshot shows this:

Eclipse

In the next section, we will take a look at how to configure an API key and add permissions that will help us to deploy our application.

主站蜘蛛池模板: 大庆市| 江油市| 佛教| 新化县| 玛多县| 奉节县| 道孚县| 青田县| 应城市| 栾川县| 蚌埠市| 石家庄市| 沅陵县| 广丰县| 永清县| 惠安县| 英吉沙县| 南江县| 平泉县| 吉安市| 靖安县| 乌苏市| 精河县| 淄博市| 扎囊县| 嵊州市| 武宣县| 西盟| 焉耆| 亚东县| 陵水| 双柏县| 扶余县| 开封县| 沽源县| 三原县| 视频| 江山市| 友谊县| 白山市| 滁州市|