Android Basic Library creation and usage

From RidgeRun Developer Connection
Jump to: navigation, search

Introduction

This wiki will guide the reader to the process of creating a Android basic Library using the newest and only accepted IDE Android Studio. The reader should have installed the latest versions of Android Studio and the Android SDK. If the Library is intended to be used on a real device then a proper phone/tablet should be connected to the PC, otherwise the internal Emulator shall be used.

Gradle

Grade is the base system that Android adopted for compiling and installing applications. In the past, Eclipse and normal Makefiles were used, so far they are deprecated.

This wiki doesn't provide much insights about the Gradle system, as the writer is not familiar with it, but some important details will be provided.

Procedure to create a Library

Follow the steps explained on this link:

http://code.tutsplus.com/tutorials/creating-and-publishing-an-android-library--cms-24582

Nevertheless, when trying to use the library on the app directory, it launches properly but it is not used on the finak .apk. To overcome this issue, the next steps are required:

1) File -> Project Structure -> Modules: If this section has the library recently created, then just add it as dependency for the 'app' module.

2) To add it as 'app' dependency module, move to the Dependencies tab, there add a new one by pressing the '+' symbol.

3) Select the module with the extension '.aar'. It is usually located under the directory <LIBRARY>/build/outputs/aar.

4) Re-Sync Gradle

With this, after launching the application it should show the custom XML and work properly.