This document outlines the steps to create and publish an Android library. Below is a guide based on the process followed to create and publish the TextModifier library.
- Start by creating a new Android project in Android Studio.
- Add a new module by selecting Android Library.
- Update the
settings.gradle
file to include the module:include ':mylibrary'
- Add the module to your app's
build.gradle
file:implementation project(':mylibrary')
- Write and test the code in the library module.
- Test the library's functionality by accessing it from the
MainActivity
or another component in your app.
- Once the library works as expected, prepare it for publishing.
- Add the following to the library module's
build.gradle
file:
plugins {
id 'maven-publish'
}
- Add the following under dependency resolution management:
repositories { maven { url "https://jitpack.io" } }
tasks.register("prepareArtifacts") {
dependsOn("assembleRelease")
}
publishing {
publications {
create<MavenPublication>("release") {
afterEvaluate {
from(components["release"])
}
groupId = "com.github.PanktiSP13"
artifactId = "TextLibrary"
version = "1.0.2"
}
}
}
- Run the following commands in the Android Studio terminal:
./gradlew assembleRelease ./gradlew publishReleasePublicationToMavenLocal
- Ensure the build succeeds.
- Push your code to GitHub.
- Create a new tag for the release:
git tag 1.0.0 git push origin 1.0.0
- Visit JitPack and search for your GitHub repository.
- Locate the recently released code and click Get it!
- Remove the module from
settings.gradle
andbuild.gradle
in the app module. - Add the library as a dependency:
dependencies { implementation "com.github.PanktiSP13:TextLibrary:1.0.2" }
- Run your app and verify the library functions as expected.
By following these steps, you can successfully create and publish an Android library.