I am trying to create a simple learning project with AndroidAnnotations, which will work with REST calls. I have followed this tutorial
https://github.com/androidannotations/androidannotations/wiki/Rest-API#rest
but with no luck. Project builds successfully, but at runtime, my @RestService is always null and I cannot get it to work.
Here is how my structure looks like:
build.gradle
apply plugin: 'com.android.application'
def AAVersion = '4.3.0'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile "org.androidannotations:rest-spring-api:$AAVersion"
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}
Interface (separate file):
@Rest(rootUrl = "https://api.github.com", converters = {StringHttpMessageConverter.class})
public interface GithubClient {
@Get("/search/repositories?q={searchString}")
GitResult getResult(@Path String searchString);
}
MainActivity:
public class MainActivity extends AppCompatActivity {
@RestService
GithubClient restClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Click(R.id.btn_Request)
void requestCall(){
searchAsync();
}
@Background
void searchAsync(){
try {
GitResult result = restClient.getResult("angular");
} catch (RestClientException e){
Log.e("Rest error",e.toString());
}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.githubbrowser">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity_">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Am I missing any package, or what am I doing wrong here? Any help or recommendations would be highly appreciated.
So the problem was that I was missing the following dependencies under build.gradle:
compile "org.androidannotations:rest-spring:$AAVersion"
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'