Я слежу за этим облаком Google Обращение к API Backend из клиента Android учебное пособие.
В разделе «Создание объекта службы» он отображает фрагмент кода для включения (я скопировал его в свой файл MainActivity.java)
Tictactoe.Builder builder = new Tictactoe.Builder(
AndroidHttp.newCompatibleTransport(), new GsonFactory(), null);
service = builder.build();
Но он не объясняет, как создать экземплярсервисный объект (3-я строка).Я потратил несколько часов, пытаясь выяснить это (кажется, связано с com.google.android.gms: play-services: 6.5+)
Кто-нибудь знает, что это за «сервисный» объект, как создать его экземпляр инеобходимые ему зависимости?
MainAcitivity:
package com.example.google_cloud_sql_test;
import android.app.Service;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.google_cloud_sql_test.echo.Echo;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.json.gson.GsonFactory;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Echo.Builder builder = new Echo.Builder(
AndroidHttp.newCompatibleTransport(), new GsonFactory(), null);
service = builder.build();
}
}
build.gradle (проект)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (приложение)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.google_cloud_sql_test"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/appengine-api-1.0-sdk-1.9.68.jar')
implementation files('libs/commons-codec-1.10.jar')
implementation files('libs/commons-fileupload-1.3.3.jar')
implementation files('libs/commons-io-2.2.jar')
implementation files('libs/commons-lang3-3.2.1.jar')
implementation files('libs/commons-logging-1.2.jar')
implementation files('libs/endpoints-framework-2.2.0.jar')
implementation files('libs/endpoints-management-control-appengine-all-1.0.11.jar')
implementation files('libs/google-api-client-1.25.0.jar')
implementation files('libs/google-api-client-appengine-1.25.0.jar')
implementation files('libs/google-api-client-servlet-1.25.0.jar')
implementation files('libs/google-http-client-1.25.0.jar')
implementation files('libs/google-http-client-appengine-1.25.0.jar')
implementation files('libs/google-http-client-jackson2-1.25.0.jar')
implementation files('libs/google-http-client-jdo-1.25.0.jar')
implementation files('libs/google-oauth-client-1.25.0.jar')
implementation files('libs/google-oauth-client-appengine-1.25.0.jar')
implementation files('libs/google-oauth-client-servlet-1.25.0.jar')
implementation files('libs/guava-20.0.jar')
implementation files('libs/httpclient-4.5.5.jar')
implementation files('libs/httpcore-4.4.9.jar')
implementation files('libs/j2objc-annotations-1.1.jar')
implementation files('libs/jackson-annotations-2.9.6.jar')
implementation files('libs/jackson-core-2.9.6.jar')
implementation files('libs/jackson-databind-2.9.6.jar')
implementation files('libs/jackson-dataformat-yaml-2.4.5.jar')
implementation files('libs/jackson-datatype-joda-2.4.5.jar')
implementation files('libs/javax.inject-1.jar')
implementation files('libs/jdo2-api-2.3-eb.jar')
implementation files('libs/joda-time-2.2.jar')
implementation files('libs/jsr305-3.0.1.jar')
implementation files('libs/servlet-api-2.5.jar')
implementation files('libs/slf4j-api-1.6.3.jar')
implementation files('libs/slf4j-nop-1.7.21.jar')
implementation files('libs/snakeyaml-1.12.jar')
implementation files('libs/swagger-annotations-1.5.9.jar')
implementation files('libs/swagger-core-1.5.9.jar')
implementation files('libs/swagger-models-1.5.9.jar')
implementation files('libs/transaction-api-1.1.jar')
implementation files('libs/validation-api-1.1.0.Final.jar')
compile 'com.google.http-client:google-http-client-gson:1.19.0'
// BEGIN Google APIs
// Play Services will validate the application prior to allowing OAuth2 access.
compile 'com.google.android.gms:play-services:6.5+'
// 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.21.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')
}
// 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.21.0')
{
// Exclude play services, since we're not using this yet.
exclude(group: 'com.google.android.gms: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.21.0') {
exclude(group: 'com.google.android', module: 'android')
}
// This is used by the Google HTTP client library.
compile(group: 'com.google.guava', name: 'guava', version: '20.0')
}