Appcelerator Blog

The Leading Resource for All Things Mobile

Integrating an external library in an Android module

0 Flares 0 Flares ×
In my previous blog post I talked about the Module Development Guide reference modules available for iOS and Android and how you can use them to develop your own custom modules. That should provide you with a good foundation for your module development needs. But one of the primary motivations for developing a Titanium module is to expose the methods and properties of an external library. In this post we’re going to look at one way to incorporate an external library into your Android module.

Add External Library

For this discussion we’re going to look at integrating the Google AdMob library into our module. The complete source to the Admob module can be found in our public modules repository on GitHub. The first thing that must be done is to download the jar file for the external library. In this case, the external library file is GoogleAdMobAdsSdk-4.1.1.jar. Place this file into the ‘lib’ folder of your module project: android/lib/googleadmobadssdk-4.1.1.jar

Add External Reference

Next we need to let the project know that we want this library packaged with the module. This requires that the .classpath file be updated with the path to the library. If you are using Eclipse for your development, then select project->properties from the menu, select “Java Build Path” in the left panel and then select the “Libraries” tab. project-properties-libraries Now click “Add External JARs…” and locate the GoogleAdMobAdsSdk-4.1.1.jar file in your project folder. add-external-jars Click “OK” to add the JAR file to your project. If you now look at your .classpath file in the project folder you should see an entry for your JAR file. If you are not using Eclipse then you can manually edit the .classpath file and add this entry.

Update timodule.xml

At this point you have added the external library to your module project. If your module requires entries in the application’s manifest file, you will need to update the timodule.xml file. The entries in the timodule.xml file are merged into the androidmanifest.xml file when an application that includes your module is built. In our example we do require an entry for the Admob activity and a couple of permission settings. The timodule.xml file should be updated as follows:

Import Classes

Your external library is now ready to be used in your module. All that is left to do is import the classes and implement your module classes, methods, properties, and notifications. To wrap up our example, we can import the required AdMob classes and begin defining our classes.

Resources

Module Development Guide Reference Modules blog post Module Development Guide Reference Modules Admob Module Module Developer Guide for Android
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

1 Comment

  1. Brad Ball

    What about including a library that contributes resources (such as some of the libraries needed for the google cast sdk)? With Android, if a library contributes resources, you can’t just include it’s jar file, you have to include a reference to the library project. Is this possible with titanium modules?

Comments are closed.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×