Не мога да импортирам крайна точка на машината на приложението в моя 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)


Уверете се, че във вашия app gradle имате следната зависимост:

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

Съветът беше предоставен от Morad и първоначално беше за нещо друго, но реши и този проблем.

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