Не удается импортировать конечную точку ядра приложения в мой EndpointsAsyncClass в Android Studio

Я пытаюсь создать свою собственную версию этого EndpointsAsyncClass на Github. Вот моя реализация:

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 Studio продолжает говорить мне, что я должен переместить класс конечной точки в модуль приложения. Помимо того, что это звучит возмутительно, я сейчас следует руководству и ничего об этом не упоминает. Когда я пытаюсь сделать это с помощью метода, указанного в совете, он утверждает, что пакет даже не существует. И да, он существует, и имя на импорте действительно его имя. Что мне не хватает?


person pimmen    schedule 07.09.2014    source источник


Ответы (2)


Убедитесь, что в вашем приложении есть следующая зависимость:

dependencies {
compile project(path: ':mymodule', configuration: 'android-endpoints')
}

Надеюсь, это сработает для вас.

person foolioJones    schedule 26.11.2014

Был еще один способ, который помог после того, как я попробовал несколько вещей; добавьте эти зависимости для app-engine.

// 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.+')

Совет был предоставлен Морадом и изначально касался чего-то другого, но решил и эту проблему.

person pimmen    schedule 08.09.2014
comment
Какая зависимость? Этот пост бесполезен сам по себе - person Ojonugwa Jude Ochalifu; 22.04.2015
comment
Отредактировал мой пост, чтобы объяснить, какие зависимости были добавлены. - person pimmen; 28.04.2015
comment
Это не решает проблему с Registration - person Shajeel Afzal; 04.12.2015