How do i make an android library

How do I create my own Android development library to be used in every program you write?


I am a Delphi programmer and have written hundreds of classes and routines over the years that I can use in any Delphi program I write.

These Library is called dlib and can used in every Delphi program by putting this folder in my library path and using one of the units in the usage section of a Delphi unit.

I'm completely new to Java and Android development and wonder how to do this in a similar way.

My question: How can I write my own classes, put them in a global folder and use these classes and routines in every Android program I write ?

I know this is a basic question that I can probably figure out by searching Google and trying it out in Eclipse. However, if someone can put me on the right track, I know I will save a lot of time.

Many Thanks.


Reply:


You need to create an Android library project. Create an Android project in Eclipse, enter Project Properties -> Android and check the isLibrary property. Now you can add this library to your Android application project by adding it to the list on the same property page.

More detailed instructions here in the Working with Library Projects section





Instructions for creating a library in Android Studio:

Create a library module

Proceed as follows to create a new library module in your project:

  1. click on File> New> New Module .

  2. By doing Create new modules Window that pops up, click Android Library, then click Next.

    There is also an option to create one Java library that creates a traditional JAR file. A JAR file is useful for many projects, especially if you want to share code with other platforms. However, you cannot include Android resources or manifest files, which is very useful for code reuse in Android projects. Hence, this guide will focus on building Android libraries.

  3. Name your library and select a minimum SDK version for the code in the library. Then click on Complete .

After the Gradle project synchronization is complete, the library module is displayed on the left in the Project window displayed. If you don't see the new module folder, make sure you are in the Android view.

Convert an app module to a library module

If you have an existing app module with all of the code that you want to reuse, here's how to turn it into a library module:

  1. Open the file at the module level.

  2. Delete the line for the. Only an Android app module can define this.

  3. At the top of the file should read the following



    appear: Change the following:



    Save the file and click Tools> Android> Sync project with Gradle files .



When your library is in Java files, which are made up of Java code. You can find a very detailed tutorial on using the library at mobile.tutsplus.com. Link below:

http://mobile.tutsplus.com/tutorials/android/android-essentials-creating-android-compliant-libraries/

For example, I wanted to use Chrisbanes' Pull To Refresh library on Github.com here https://github.com/chrisbanes/Android-PullToRefresh/tree/master/library. The structure of the library consists of an Android app. It has the following form:

How to use Eclipse:

  1. Create a new project in Eclipse. Give your project a name. Select "Create project from existing source". Under "Location", select the location of the root folder that contains the files mentioned above. Choose your destination and click Finish.
  2. Select the properties of the newly created project. Select the "Android" option. Activate the "Is library" check box if it is not already activated. Close properties.
  3. Add a reference to the library from the project that should use this library. Select your project that uses this library. Open Properties. Select the "Android" option. Down on the "Is Library". Do not select the Is Library check box. Click the "Add" button on the right. Your project that you created in steps 1 and 2 should be listed for selection. Select it and click Apply. Close properties.
  4. You can now reference the classes from your project.


With Java you create a Java Archive (JAR) that contains all your classes (* .class files) of this library and the JAR file is Your library.

To use it just add it to the Classpath .

(For "jar" and "classpath": basic Java concepts please use Google to find tutorials. You have to understand these concepts anyway, the sooner the better;))




Convert your entire class to Java and create a JAR file. Use this jar in your Android project by copying it to libs / folder and then adding it to the build path. Clean the project and run it.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.