{"id":6675,"date":"2021-03-15T13:57:01","date_gmt":"2021-03-15T08:27:01","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=6675"},"modified":"2021-03-15T13:57:01","modified_gmt":"2021-03-15T08:27:01","slug":"developing-android-library","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/","title":{"rendered":"Developing Android Library"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Why is there a need to develop a library? Well, developing libraries help use their feature in many applications. You must have seen its live example in forms of payment gateway, chat library, retrofit, butterknife and many more. Creating a library in Android is effortless. Android library compiles into AAR file which also provides you with a user interface.<strong> In this blog, we will dive into learning how to create a library. We evaluate four key issues:\u00a0<\/strong><\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How a library can be built (what should be kept in mind)<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Include libraries for a project<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Initializing a library.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Publishing a library.<\/span><\/li>\n<\/ul>\n<p><b>Creating the Android library:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Create a project in Android Studio. Create a module inside your project, then select the Android Library option and click Finish. Add your code inside the library module. What should be kept in mind while writing code: there should be an entry point (or how to initialize the library), how to get the callbacks of the user events(optional) and how to exit the library.\u00a0<\/span><\/p>\n<p><b>Include the library as a dependency:<\/b><b>\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400;\">In order to use library code, you can go with any of the following two ways:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>1.<\/strong> Add .aar file or .jar file\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click File &gt; New&gt; New Module<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click import .aar\/.jar Package and then hit the Next button.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Enter the location of the library and click Finish.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0While following these steps Android Studio creates build.gradle file for the library which looks like:<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0\u00a0<\/span><\/p>\n<pre class=\"lang:default decode:true\">configurations.maybeCreate(\"default\")\r\n\u00a0 \u00a0 \u00a0 artifacts.add(\"default\", file('libraryName'))<\/pre>\n<p><span style=\"font-weight: 400;\"><strong>\u00a02.<\/strong> Add the source code of the library as a module in your project:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0Click File &gt; New &gt; Import module<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Enter the location of the module and then click Next.<\/span><\/li>\n<\/ul>\n<p><strong>Now we should add the library as a dependency in the app level gradle file:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">dependencies {\r\n\u00a0 \u00a0 implementation project(\":my-library-module\")\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\"><strong>3.<\/strong> After that, sync the project.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><b style=\"font-size: 1rem;\">Initializing a library:<\/b><\/span><\/p>\n<p><span style=\"font-weight: 400;\">After adding the module to your project, the next thing which comes to our mind is how to use it? Well to initialize or enter into the library, you must write initialization code or pass values if required to the library. And this is mostly done inside the Application class of the app keeping in mind one-time initialization throughout the app. Below Snippet of code is an example of initializing a library inside the Application class:<\/span><\/p>\n<pre class=\"lang:default decode:true \">public\u00a0 class MyApplication extends Application {\r\n@override\r\npublic\u00a0 void onCreate() {\r\nsuper.onCreate();\r\n...\r\nP2PLibrary.init(new P2PLibrary.Options(this, \"Username\",\"Authkey\"));\r\n\r\n}\r\n}<\/pre>\n<p><b>Publishing your Library:<\/b><\/p>\n<p><span style=\"font-size: 1rem;\">Create a GitHub repo for your app and library. One thing to keep in mind is to add the android-mavin plugin in project\/build.gradle.<\/span><\/p>\n<pre class=\"lang:default decode:true \">dependencies {\r\n...\r\nclasspath 'com.github.decendants:android-maven-gradle-plugin:1.5'\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Push the code in Github. And then create the release tag. Open <\/span><a style=\"font-size: 1rem;\" href=\"https:\/\/jitpack.io\/\">JitPack<\/a><span style=\"font-weight: 400;\"> and lookup for your library. After this, you can get your library from Jitpack.<\/span>Then add the maven plugin and group setting inside library\/build.gradle.<\/span><\/p>\n<p><b>Conclusion<\/b><\/p>\n<p><span style=\"font-weight: 400;\">In this blog, every possible aspect of creating a library is covered, whereas some topics are discussed briefly. So for understanding how to create your own library with a small example, see <\/span><span style=\"font-weight: 400;\"><a href=\"https:\/\/medium.com\/@anujguptawork\/how-to-create-your-own-android-library-and-publish-it-750e0f7481bf\">Android toast library<\/a><\/span><span style=\"font-weight: 400;\">.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why is there a need to develop a library? Well, developing libraries help use their feature in many applications. You must have seen its live example in forms of payment gateway, chat library, retrofit, butterknife and many more. Creating a library in Android is effortless. Android library compiles into AAR file which also provides you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6676,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[588,14],"class_list":["post-6675","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-developing-android-library","tag-innovationm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Developing Android Library - InnovationM - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/developing-android-library\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Developing Android Library - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"Why is there a need to develop a library? Well, developing libraries help use their feature in many applications. You must have seen its live example in forms of payment gateway, chat library, retrofit, butterknife and many more. Creating a library in Android is effortless. Android library compiles into AAR file which also provides you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/developing-android-library\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-15T08:27:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Developing Android Library\",\"datePublished\":\"2021-03-15T08:27:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/\"},\"wordCount\":475,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/Developing-Android-Library.png\",\"keywords\":[\"Developing Android Library\",\"InnovationM\"],\"articleSection\":[\"Android\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/\",\"name\":\"Developing Android Library - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/Developing-Android-Library.png\",\"datePublished\":\"2021-03-15T08:27:01+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/Developing-Android-Library.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/Developing-Android-Library.png\",\"width\":960,\"height\":540},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/developing-android-library\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Developing Android Library\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Developing Android Library - InnovationM - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/","og_locale":"en_US","og_type":"article","og_title":"Developing Android Library - InnovationM - Blog","og_description":"Why is there a need to develop a library? Well, developing libraries help use their feature in many applications. You must have seen its live example in forms of payment gateway, chat library, retrofit, butterknife and many more. Creating a library in Android is effortless. Android library compiles into AAR file which also provides you [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/","og_site_name":"InnovationM - Blog","article_published_time":"2021-03-15T08:27:01+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Developing Android Library","datePublished":"2021-03-15T08:27:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/"},"wordCount":475,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png","keywords":["Developing Android Library","InnovationM"],"articleSection":["Android"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/developing-android-library\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/","url":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/","name":"Developing Android Library - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png","datePublished":"2021-03-15T08:27:01+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/developing-android-library\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/03\/Developing-Android-Library.png","width":960,"height":540},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/developing-android-library\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Developing Android Library"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=6675"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6675\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/6676"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=6675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=6675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=6675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}