Menu

Tree [02eefc] master /
 History

HTTPS access


File Date Author Commit
 app 2016-11-27 AlexanderR AlexanderR [ec9748] More tests, fixed some edge cases
 buildSrc 2016-11-03 AlexanderR AlexanderR [d2adc7] Added Jack compiler sample
 gradle 2016-11-03 AlexanderR AlexanderR [99d695] Updated Gradle to 2.14.1
 jackdemo 2016-11-10 AlexanderR AlexanderR [793229] Map support, fix couple of crashes, other misc ...
 lib 2017-04-05 AlexanderR AlexanderR [b7add3] Test for OneWay
 .gitignore 2016-11-03 AlexanderR AlexanderR [d2adc7] Added Jack compiler sample
 .gitmodules 2016-04-07 AlexanderR AlexanderR [be6425] Fixed RetroLambda plugin submodule, fix jacoco,...
 .travis.yml 2016-11-03 AlexanderR AlexanderR [d2adc7] Added Jack compiler sample
 CONTRIBUTING 2016-05-08 AlexanderR AlexanderR [006857] Updated CONTRIBUTING
 COPYING 2016-04-07 AlexanderR AlexanderR [9812a8] Added license information
 ChangeLog 2017-04-05 AlexanderR AlexanderR [02eefc] Updated README
 LICENSE 2016-04-07 AlexanderR AlexanderR [9812a8] Added license information
 README.md 2017-04-05 AlexanderR AlexanderR [02eefc] Updated README
 build.gradle 2016-11-10 AlexanderR AlexanderR [793229] Map support, fix couple of crashes, other misc ...
 deployment.gradle 2016-11-24 AlexanderR AlexanderR [44717d] Released 0.3.5
 gradle.properties 2016-11-03 AlexanderR AlexanderR [99d695] Updated Gradle to 2.14.1
 gradlew 2016-11-03 AlexanderR AlexanderR [99d695] Updated Gradle to 2.14.1
 gradlew.bat 2016-11-03 AlexanderR AlexanderR [99d695] Updated Gradle to 2.14.1
 settings.gradle 2016-11-03 AlexanderR AlexanderR [d2adc7] Added Jack compiler sample

Read Me

Branch Build Status
Master Master Build status Master Coverage Status
Dev Dev Build status Dev Coverage Status

AIDL2

Traditionally "aidl" refers to several related but distinct concepts:

  • the AIDL interface definition language;
  • .aidl files (which contain AIDL);
  • the aidl generator which transforms AIDL into client/server IPC interfaces.

This is a replacement for Google's aidl generator tool. Instead of parsing very limited DSL AIDL2
uses Java annotation processing framework to generate Java implementation, based on Java
interface code. This allows you to extend from other interfaces, annotate your interface classes,
use generics and other features of Java language.

AIDL2 and Android aidl tool

Unlike Google's code generator, which is implemented as standalone C++ executable,
AIDL2 is an annotation processor, that is — a plugin for Java compiler. It works automatically
by adding jar file to project dependencies.

Better integration with compiler gives aidl2 complete understanding of involved types.
In addition to types, supported by aidl tool, AIDL2 allows use of

  • Generic Collections and Maps
  • IInterface subtypes (both from AIDL2 and aidl tool)
  • Externalizable/Serializable types
  • Multi-dimensional arrays
  • Void — ignored during (de)serialization, always evaluates to null

All generated code is human-readable and well-formatted.

You can learn more about project features in project wiki.

Current status

This project is in alpha stage. It is not nearly as well-tested as original aidl tool, but
all features are there. If you decide to use it, make sure to read the generated code, to
avoid any unpleasant surprises.

Usage

Download

Add the library to project:

dependencies {
  compile 'net.sf.aidl2:compiler:0.4.0'
}

Write an interface with required methods. It must extend android.os.IInterface. Furthermore,
each method must declare android.os.RemoteException to be thrown.
Annotate the interface with @AIDL.

@AIDL
public interface RemoteApi extends IInterface {
  String sayHello() throws RemoteException;
}

Retrive generated proxy/stub using InterfaceLoader.

Service code:

public IBinder onBind(Intent intent) {
  RemoteApi serviceApi = new RemoteApi() {
    public String sayHello() {
      return "Hello world";
    }

    public IBinder asBinder() {
      return InterfaceLoader.asBinder(this, RemoteApi.class);
    }
  };
  return serviceApi.asBinder();
}

Caller code:

public void onServiceConnected(ComponentName name, IBinder serviceBinder) {
  try {
    final RemoteApi serviceApi = InterfaceLoader.asInterface(serviceBinder, RemoteApi.class);

    final String callResult = serviceApi.sayHello();

    Toast.makeText(this, "Received message \"" + callResult + '"', Toast.LENGTH_SHORT).show();
  } catch (RemoteException e) {
    Toast.makeText(this, "Service error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
  }
}

Defining an interface

You can specify any number of parameters, including varargs. Parameters and
return values must be of types, supported by android.os.Parcel as well as extra types,
listed above. You can use tricky generic types if you want, but make sure, that those can be
interpreted as one of supported types:

@AIDL
public interface RemoteApi extends IInterface {
  <T extends Runnable> void exampleMethod(T runnableParameter) throws RemoteException;
}

will fail to compile with error, because Parcel does not support Runnables.

@AIDL
public interface RemoteApi extends IInterface {
  <T extends Runnable & Parcelable> T exampleMethod() throws RemoteException;
}

will compile and generate code, using writeParcelable and readParcelable to pass "runnableParameter"
between processes.

@AIDL
public interface RemoteApi extends IInterface {
    void exampleMethod(Date[] dateArray) throws RemoteException;
}

will compile and use readSerializable and writeSerializable to passs "dateArray" between processes.

Other documentation

Read project wiki for in-depth documentations and some useful links.