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

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.

主站蜘蛛池模板: 钟山县| 白沙| 永登县| 大理市| 苏尼特左旗| 沛县| 宣汉县| 岳阳市| 梨树县| 五指山市| 宣恩县| 虹口区| 东乡| 竹山县| 新竹县| 阿坝县| 威宁| 鞍山市| 云安县| 竹北市| 嘉荫县| 富锦市| 会昌县| 定远县| 梨树县| 乐陵市| 老河口市| 古田县| 潼南县| 西平县| 凤阳县| 博乐市| 乌兰浩特市| 平顶山市| 唐海县| 赫章县| 黄浦区| 定日县| 佳木斯市| 吉安县| 天气|