このページでは、App Engine 用に Cloud Endpoints Frameworks でビルドしたバックエンド API を Android クライアントから呼び出す方法について説明します。
クライアント ライブラリを生成する
Android クライアントはクライアントが使用しているバックエンド API から生成されたクライアント ライブラリを必要とします。現時点でクライアント ライブラリが存在しない場合は、クライアント ライブラリを生成するで詳細をご確認ください。このドキュメントで説明する手順は、Android クライアント プロジェクトにクライアント ライブラリを追加するためのものです。
プロジェクトのセットアップを行う
この手順では Android Studio を使用します。 まだ設定していない場合は、Android Studio を設定して、フレームワークを使用するクライアントをサポートするようにしてください。
プロジェクトの構成
Android Studio では、従属関係やその他の設定のために build.gradle ファイルをプロジェクトで使用します。デフォルトで、Android Studio は、親プロジェクト レベルの build.gradle ファイルと Android アプリ固有のファイルを Android モジュール内に作成します。下記の手順は Android モジュール内のアプリ固有の build.gradle に関する説明です。
build.gradle を構成するには、次の手順を実行します。
build.gradleをダブルクリックして開きます。開いたファイルを編集し下記の行を追加します。
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } } apply plugin: 'com.android.application' repositories { mavenCentral() mavenLocal() } android { compileSdkVersion 26 defaultConfig { applicationId "com.mycompany.myapp" minSdkVersion 17 targetSdkVersion 26 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/DEPENDENCIES' } } dependencies { implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' // BEGIN Google APIs // Play Services will validate the application prior to allowing OAuth2 access. implementation 'com.google.android.gms:play-services-auth:16.0.0' implementation 'com.google.android.gms:play-services-identity:16.0.0' // The following lines implement maven imports as defined at: // https://github.com/googleapis/google-api-java-client/wiki/Setup-Instructions // Add the Google API client library. implementation('com.google.api-client:google-api-client:1.28.0') { // 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'