---
title: "Creating libraries for Android applications"  
description: "Hi everyone in this article I’m explaining about Creating libraries for Android applications"  
author: "Manoj Pandey"  
published: 2015-03-12  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1653/creating-libraries-for-android-applications  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# Creating libraries for Android applications

Android library [projects](https://www.mindstick.com/forum/161801/what-is-the-use-of-github-projects-and-how-does-it-relate-to-agile-methodology) provide reusable code and [resources](https://www.mindstick.com/interview/1265/what-are-the-different-types-of-resources-through-which-cold-fusion-can-communicate) that can save you time and effort when developing apps — you don’t have to keep “reinventing the wheel.”\

Android project can use code contained in JAR files (Java [libraries](https://answers.mindstick.com/qa/49244/which-company-is-ahead-in-classification-of-data-for-libraries-innovations)). It is also possible to create libraries modules which can be used as dependencies in Android projects. These modules allow you to store [source code](https://www.mindstick.com/forum/23271/is-there-a-way-to-get-the-source-code-from-an-apk-file) and Android resources which can be shared between several other Android projects.

##### Here I am creating sample of libraries with access it in another application.

##### \
1. Create an android project for library

##### ![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/77f60350-70df-46c1-8cc8-20998934702f.png)

##### 2. Click Next and Mark this project as library

##### \
![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/ccb434e4-00c4-43f9-85f8-3af4f731474d.png)\

3. Add class in Library

```
public class MyDemo {     public String getMyResult() {           return "Android Library Application......!";     } }
```

\

4. Create a new Android Project

5. Add library in this project , use some following steps-:

· Right click in [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) and choose [Properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) as given below

![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/14852548-8cb2-45fb-b30a-6ffb8b1e24f0.png)\

· Now open a window choose Android as given below

![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/e7188f7a-9018-4507-abda-7db6d77ef80f.png)\

· Press add button and [choose your](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) library then click ok

![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/1c7e0034-759f-4b4d-8135-724257a29d5f.png)

After click ok press Apply button.

![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/75aaa89c-863a-454b-8472-2fbde6793ec5.png)

Now you have imported library in your [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) project.

6. Add following code in MainActivity.class

```
package com.example.androiddemolibrary; import com.example.mylibrary.MyDemo; import android.os.Bundle;import android.app.Activity; import android.view.Menu;import android.widget.TextView; public class MainActivity extends Activity {     TextView textView;      @Override     protected void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);           textView = (TextView) findViewById(R.id.mytextview);                      // Call constructor of library class           MyDemo demo = new MyDemo();            // call method of library class  String
           text = demo.getMyResult();           textView.setText(text);      }      @Override     public boolean onCreateOptionsMenu(Menu menu) {           // Inflate the menu; this adds
           items to the action bar if  it is present.           getMenuInflater().inflate(R.menu.main, menu);           return true;     } }
```

Now run your application

![Creating libraries for Android applications](https://www.mindstick.com/mindstickarticle/68b97320-081d-4a93-bfa3-9fe4be2a9ae1/images/e4b87adf-7751-4938-9d17-21d07f4b3c94.png)

---

Original Source: https://www.mindstick.com/articles/1653/creating-libraries-for-android-applications

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
