[英]Using Retrofit with a Flex Mobile app
I'm working on a Flex Mobile app for Android with a native extension. 我正在使用适用于本机扩展的Android Flex Mobile应用程序。 I'm trying to use Retrofit in the Java code, but the Retrofit calls are failing.
我正在尝试在Java代码中使用Retrofit,但是Retrofit调用失败。
I have the following interface defined: 我定义了以下接口:
public interface GitHubService {
@GET("/repos/{owner}/{repo}/contributors")
List<Contributor> contributors(
@Path("owner") String owner,
@Path("repo") String repo
);
}
Then I have an AsyncTask
invoked from the appropriate point in my Java code. 然后,我从Java代码的适当位置调用了
AsyncTask
。 Its doInBackground
method looks like this: 其
doInBackground
方法如下所示:
@Override
protected String doInBackground(String... arg0) {
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.create();
RestAdapter restAdapter = new RestAdapter.Builder().setServer("https://api.github.com")
.setConverter(new GsonConverter(gson))
.build();
GitHubService service = restAdapter.create(GitHubService.class);
List<Contributor> contributors = service.contributors("square", "okhttp");
for (Contributor contributor : contributors) {
Log.d("FooTask", contributor.login + " - " + contributor.contributions);
}
return null;
}
From all this, I'm expecting to see a list printed in LogCat; 从所有这些,我希望看到在LogCat中打印的列表。 instead I get the following exception:
相反,我得到以下异常:
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
...
Caused by: java.lang.IllegalStateException: No Retrofit annotation found on parameter 1 of contributors
Is there a way to make Retrofit work inside a native extension with Flex Mobile? 有没有办法使Flexfit在Flex Mobile的本机扩展中工作?
This currently isn't possible. 目前这是不可能的。 ADT strips all annotations from java classes in its compilation process for dalvik.
ADT在dalvik的编译过程中会从Java类中剥离所有注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.