首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Android中将应用程序引擎端点导入我的EndpointsAsyncClass

无法在Android中将应用程序引擎端点导入我的EndpointsAsyncClass
EN

Stack Overflow用户
提问于 2014-09-07 14:51:27
回答 2查看 1.1K关注 0票数 4

我尝试在Github上构建我自己的EndpointsAsyncClass版本。以下是我的实现:

代码语言:javascript
复制
package com.example.pontuse.helloendpointsproject;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Pair;
import android.widget.Toast;

import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import com.google.devrel.samples.mymodule.api.commentEndpoint.CommentEndpoint;

import java.io.IOException;

/**
 * Created by pontuse on 2014-09-07.
 */
public class EndpointsAsyncTask extends AsyncTask<Pair<Context, String>, Void, String> {
private static CommentEndpoint myApiService = null;
private Context context;

@Override
protected String doInBackground(Pair<Context, String>... params) {
    if(myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver

        myApiService = builder.build();
    }

    context = params[0].first;
    String name = params[0].second;

    try {
        return myApiService.sayHi(name).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}

@Override
protected void onPostExecute(String result) {
    Toast.makeText(context, result, Toast.LENGTH_LONG).show();
}
}

然而,Android一直告诉我必须将端点类移动到我的应用程序模块中。除了这听起来很离谱之外,我现在是遵循教程,它没有提到任何关于它的事情。当我试图通过技巧中提供的方法进行操作时,它声称包甚至不存在。是的,它确实存在,而导入中的名称实际上就是它的名称。我遗漏了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-26 08:51:11

确保在您的应用程序gradle中有以下依赖项:

代码语言:javascript
复制
dependencies {
compile project(path: ':mymodule', configuration: 'android-endpoints')
}

希望这对你有用。

票数 0
EN

Stack Overflow用户

发布于 2014-09-08 11:13:54

在尝试了一些东西之后,还有另一种方法可以帮助您:为应用程序引擎添加这些依赖项。

代码语言:javascript
复制
// Play Services will validate the application prior to allowing OAuth2 access.
compile(group: 'com.google.android.gms', name: 'play-services', version: '3.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.+')

技巧是由Morad提供,最初是关于其他东西的,但也解决了这个问题。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25711468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档