问题描述
我尝试构建自己的版本在Github上。这是我的实现:
I try to build my own version of this EndpointsAsyncClass on Github. Here's my implementation:
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一直告诉我必须移动我的端点类到我的应用程序模块。除了这听起来很离谱的事实,我现在还是,并没有提到任何有关它的信息。当我尝试通过提示中提供的方法进行操作时,它声称该软件包不存在。是的,它确实存在,导入的名字真的是它的名字。我缺少什么?
However, Android Studio keep telling me I have to move my endpoint class to my app module. Beside the fact that it sounds outrageous, I'm currently following a tutorial and it doesn't mention anything about it. When I try to do it through the method provided in the tip, it claims the package doesn't even exist. And yes, it does exist and the name on the import really is it's name. What am I missing?
推荐答案
确保在您的应用程序中有以下依赖关系:
Make sure in your app gradle you have the following dependency:
dependencies {
compile project(path: ':mymodule', configuration: 'android-endpoints')
}
希望这会对您有用。
这篇关于无法将应用引擎端点导入Android Studio中的EndpointsAsyncClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!