Search This Blog

18 February 2012

AIDL Step 1: Creating the API

malachi@onyx:~/work/apkextensions$ mvn archetype:generate -DarchetypeCatalog=http://repository-malachid.forge.cloudbees.com/public-snapshot/archetype-catalog.xml
[INFO] Scanning for projects...
[INFO]                                                                       
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: http://repository-malachid.forge.cloudbees.com/public-snapshot/archetype-catalog.xml -> org.eoti.kryten:kryten-archetype (kryten-archetype)
2: http://repository-malachid.forge.cloudbees.com/public-snapshot/archetype-catalog.xml -> org.eoti.galatea:galatea-archetype (galatea-archetype)
3: http://repository-malachid.forge.cloudbees.com/public-snapshot/archetype-catalog.xml -> org.eoti.archtest:archtest-archetype (archtest-archetype)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 2
Define value for property 'groupId': : org.eoti.android.test.apkextensions.api
Define value for property 'artifactId': : API
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  org.eoti.android.test.apkextensions.api: :
Confirm properties configuration:
groupId: org.eoti.android.test.apkextensions.api
artifactId: API
version: 1.0-SNAPSHOT
package: org.eoti.android.test.apkextensions.api
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: galatea-archetype:1.1-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.eoti.android.test.apkextensions.api
[INFO] Parameter: artifactId, Value: API
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: org.eoti.android.test.apkextensions.api
[INFO] Parameter: packageInPathFormat, Value: org/eoti/android/test/apkextensions/api
[INFO] Parameter: package, Value: org.eoti.android.test.apkextensions.api
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: org.eoti.android.test.apkextensions.api
[INFO] Parameter: artifactId, Value: API
[WARNING] Don't override file /home/malachi/work/apkextensions/API/src/main/android/res/values/strings.xml
[WARNING] Don't override file /home/malachi/work/apkextensions/API/src/main/android/res/layout/main.xml
[INFO] project created from Archetype in dir: /home/malachi/work/apkextensions/API
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:20.979s
[INFO] Finished at: Sat Feb 18 06:56:29 PST 2012
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------


delete API/src/main/java/org/eoti/android/test/apkextensions/api/APIActivity.java
remove that activity from API/src/AndroidManifest.xml

create an API/src/main/java/org/eoti/android/test/apkextensions/api/v1/Registration.java
package org.eoti.android.test.apkextensions.api.v1;

import android.os.Parcel;
import android.os.Parcelable;

public class Registration
implements Parcelable
{
    private String name = "unset";

    public static final Creator<Registration> CREATOR = new Creator<Registration>()
    {
        @Override
        public Registration createFromParcel(Parcel parcel) {
            return new Registration(parcel);
        }

        @Override
        public Registration[] newArray(int size) {
            return new Registration[size];
        }
    };

    public Registration()
    {

    }

    public Registration(Parcel in)
    {
        readFromParcel(in);
    }

    public void setName(String name){this.name = name;}
    public String getName(){return name;}

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(getName());
    }

    public void readFromParcel(Parcel in)
    {
        setName(in.readString());
    }
}

create an API/src/main/java/org/eoti/android/test/apkextensions/api/v1/Registration.aidl
package org.eoti.android.test.apkextensions.api.v1;

parcelable Registration;


create an API/src/main/java/org/eoti/android/test/apkextensions/api/v1/IServer.aidl
package org.eoti.android.test.apkextensions.api.v1;

import org.eoti.android.test.apkextensions.api.v1.Registration;

interface IServer
{
    void register(inout Registration registration);
    void unregister(in String registrationName);
}
The 'inout' bit specifies that the object could be modified by the server. Not really necessary in this particular case, but I can see where it might be useful for registration type objects (adding shared keys to it, expiration dates, etc) so I put it in.

in API/pom.xml
change:  
<packaging>apk</packaging>
to:  
<packaging>apklib</packaging>

Remove these executions:
                   
                    <execution>
                        <id>android-undeploy</id>
                        <phase>pre-clean</phase>
                        <goals>
                            <goal>undeploy</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>android-deploy</id>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                   
                       
                   
                   
also, make sure to either setup a keystore or, as in this case, remove the signing by removing the following:
                    <sign>
                        <debug>false</debug>
                    </sign>
and:
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>signing</id>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <phase>package</phase>
                        <inherited>true</inherited>
                        <configuration>
                            <archiveDirectory></archiveDirectory>
                            <includes>
                                <include>target/*.apk</include>
                            </includes>
                            <!-- see http://developer.android.com/guide/publishing/app-signing.html -->
                            <keystore>android.keystore</keystore>
                            <storepass>YOUR_STOREPASS_HERE</storepass>
                            <keypass>YOUR_KEYPASS_HERE</keypass>
                            <alias>YOUR_ALIAS_HERE</alias>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


At this point, you can verify that it compiles. 
Make sure that you have the emulator running or device connected and compile it:
malachi@onyx:~/work/apkextensions$ cd API
malachi@onyx:~/work/apkextensions/API$ mvn clean install


Next up, AIDL Step 2: Creating the Service

No comments:

Post a Comment