4.0.0 migration guide

Tamas Vegh edited this page Sep 7, 2017 · 4 revisions

AndroidAnnotations is now modularized

The library is now split into smaller modules. This means if you are using annotations were which split into a module, you have to add new dependencies, and change the imports for those annotations.

@OrmLiteDao

For using OrmLiteDao, addd these new dependencies in your build.gradle:

compile "org.androidannotations:ormlite-api:4.0.0"
apt "org.androidannotations:ormlite:4.0.0"

Change your imports to

org.androidannotations.ormlite.annotations.OrmLiteDao

Otto

For using Otto with AA, add this dependency in your build.gradle:

apt "org.androidannotations:otto:4.0.0"

Rest client

For using the REST client, add these new dependencies in your build.gradle:

compile "org.androidannotations:rest-spring-api:4.0.0"
apt "org.androidannotations:rest-spring:4.0.0"

Change your imports to

org.androidannotations.rest.spring.annotations.Rest // etc
org.androidannotations.rest.spring.api.RestClientHeaders // etc

@RoboGuice

For using @RoboGuice, add these new dependencies in your build.gradle:

compile "org.androidannotations:roboguice-api:4.0.0"
apt "org.androidannotations:roboguice:4.0.0"

Change your imports to

org.androidannotations.roboguice.annotations.RoboGuice

Injected Fragment view fields are cleared

We clear injected view fields (@ViewById and @ViewsById) by setting them to null in Fragment#onDestroyView(). If you access these views after this lifecycle event, you will get NullPointerExceptions. You can guard against this by the new @IgnoreWhen annotation:

@IgnoreWhen(IgnoreWhen.State.VIEW_DESTROYED)
void someMethodCalledAfterViewDestroyed() {
  injectedView.setText("Hello");
}

##Minimum Android version is 2.3.1

We no longer support applications with minSdkVersion below 2.3.1. It is possible your code will still work, but expect generated code may broke under lower Android versions. But you do not target ancient Android anymore, don`t you? :wink:

Minimum JDK version is 7

We no longer support JDK 6 for compilation, which is end of life years ago. You can still write Java 6 source code using a newer JDK compiler.

@ReceiverAction changes

We no longer inspect the action name from the method name if there is no annotation value specified. Also the value parameter changed to actions.

@ReceiverAction
public void simpleAction() { // AA 3.x, action = "simpleAction"

}

@ReceiverAction(actions = "simpleAction")
public void simpleAction() { // AA 4.0.0
}

##@OrmLiteDao model parameter removed This parameter was removed, but we already inspected it from the Dao class, so it was redundant.

@OrmLiteDao(helper = DatabaseHelper.class, model = Car.class) // AA 3.x
Dao<Car, Long> injectedDao;

@OrmLiteDao(helper = DatabaseHelper.class) // AA 4.0.0
Dao<Car, Long> injectedDao;

##@NoTitle annotation removed This annotations was removed, but you can get the same functionality with @WindowFeature.

@NoTitle // AA 3.x
@EActivity
public class MyActivity extends Activity {

}

@WindowFeature(Window.FEATURE_NO_TITLE) // AA 4.0.0
@EActivity
public class MyActivity extends Activity {

}

ActionBarSherlock support dropped

We no longer support ActionBarSherlock with the options menu related annotations. You should use the AppCompat Support Library instead.

@Extra and @AfterExtras changes

We no longer call setIntent() in the onNewIntent() method if you use these annotations. If you need this, you can call it yourself.

@Extra
int myExtra;

// AA 3.x called setIntent() in the overriden `onNewIntent()` method

To achieve the same behavior in AA 4.0.0:

@Extra
int myExtra;

protected void onNewIntent(Intent intent) {
  setIntent(intent);
}

All method params require annotation in @Rest clients:

We no longer allow unannotated method parameters, you must tell the processor explicitly the meaning of each method parameter.

For the the request body:

@Rest(converters = GsonHttpMessageConverter.class)
public interface MyRestClient {
  @Put
  void putEvent(Event event); // AA 3.x request body is the event variable
}

@Rest(converters = GsonHttpMessageConverter.class)
public interface MyRestClient {
  @Put
  void putEvent(@Body Event event); // AA 4.0.0
}

For the url variables:

@Rest(converters = GsonHttpMessageConverter.class)
public interface MyRestClient {
  @Get("/events/{id}"
  Event getEvent(int id); // AA 3.x the id method param is an url variable
}

@Rest(converters = GsonHttpMessageConverter.class)
public interface MyRestClient {
  @Get("/events/{id}"
  Event getEvent(@Path int id); // AA 4.0.0
}

@DefaultStringSet requires value

A mandatory argument, value was introduced for @DefaultStringSet, just like for the rest of the @DefaultXXX annotations. Usage:

@DefaultStringSet({ "John", "Mary" })
String<Set> names();

21/10/2018 The 4.5.2 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.