Android code generation with Acceleo
Summary
This tutorial covers the instalation of Acceleo and the creation of a Code Generator to model Android Applications.
Instalation and Requisites
- Eclipse IDE for Java Developeers, version 3.6.2 (Helios SR2 release).
Available at: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr2 - Acceleo (version 3.1.0)
Install "Acceleo SDK" from the "Acceleo 3.1 update site" (http://download.eclipse.org/modeling/m2t/acceleo/updates/releases/3.1) - Android Development Tools (ADT) plugin
Instructions available at: http://developer.android.com/sdk/installing.html. - Android 2.3.3 Platform (SDK and AVD)
If you can follow the "Hello, World" tutorial you have set it up correctly.
Metamodel plugin installation
Before creating the Acceleo project you must export and install the plug-in containing your DSL metamodel. Therefore, export and install the Xtext plugin (org.xtext.example.droid
) generated in the previous tutorial.
Note: If you have extracted the EMF plugin your Xtext plugin (org.emf.example.droid
) you should install it too. The tutorial forementioned contains detailed instructions on performing both operations.
Acceleo
Acceleo is a pragmatic implementation of the Object Management Group (OMG) MOF Model to Text Language (MTL) standard. So, with Acceleo you can generate code from a model through a Model to Text transformation.
In this tutorial we will cover a Model to Text transformation, generating code to an Android application from a model written in the Droid DSL (covered in the "Building the Droid DSL editor with Xtext" tutorial).
Creating a sample Android Project
0fc8d6bdc1acf60f33b8132327ca364185e86136
We are going to create a sample Android Project. This project will be our guide in the generator creation process, and will be our test to the generator.
- Open menu
File > New > Project...
- Choose
Android > Android Project
- Fill the Project Options as follows:
- Project name and Package Name:
org.android.example.droid
- Build target:
Android 2.3.3
- Application Name:
Hello Droid
- Create Activity:
org.android.example.droid.MainActivity
- Min SDK Version:
10
- Project name and Package Name:
Creating a Droid file
In order to test the generator, we need to have some source file written in our DSL language.
- Right-click the
org.android.example.droid
- Choose
New > Folder
- Create a folder named
model
- Right-click the created
model
folder - Choose
New > File
- Create a file named
hello.droid
- Paste the following code in the file contents:
//From: http://developer.android.com/resources/tutorials/hello-world.html
application "Hello, Droid" => org.android.example.droid
hello = "Hello Droid!"
screen Main {
show main
}
layout main {
# textView text_view string(hello) {
layout: {
width: fill_parent;
height: fill_parent;
}
}
}