Perfect recipe of Library Module For Android Applications

Image for post
Image for post

What are Libraries for Android applications?

Custom Android library modules

How to create an Android library module for Android

package com.example.android.rssfeedlibrary; public class RssItem { private String pubDate; private String description; private String link; private String title; public RssItem() { } public RssItem(String title, String link) { this.title = title; this.link = link; } public String getPubDate() { return pubDate; } public void setPubDate(String pubDate) { this.pubDate = pubDate; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @Override public String toString() { return "RssItem [title=" + title + "]"; } }
package com.example.android.rssfeedlibrary; import java.util.ArrayList; import java.util.List; import java.util.Random; public class RssFeedProvider { public static List<RssItem> parse(String rssFeed) { List<RssItem> list = new ArrayList<>(); Random r = new Random(); // random number of item but at least 5 Integer number = r.nextInt(10) + 5; for (int i = 0; i < number; i++) { // create sample data String s = String.valueOf(r.nextInt(1000)); RssItem item = new RssItem("Summary " + s, "Description " + s); list.add(item); } return list; } }
public class MyListFragment extends Fragment { // triggers update of the details fragment public void updateDetail(String uri) { // List<RssItem> list = RssFeedProvider .parse(uri); String itemListAsString = list.toString(); listener.onRssItemSelected(itemListAsString); }
apply plugin: 'maven' group = 'com.vogella.libraries' version = '1.0' uploadArchives { repositories { mavenLocal() } }
compile 'com.vogella.libraries:recyclerbaseadapter:1.0`

Bonus : Development considerations for library modules

Anatomy of an AAR file

Written by

Data Enthusiast, Geek, part — time blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store