HomeAndroidMethods to Publish Android Library on JitPack.io with GitHub?

Methods to Publish Android Library on JitPack.io with GitHub?


I used to be trying to find tips on how to publish the Android library on MavenCentral() and it turned out the method appears very sophisticated and troublesome. So I discovered one other straightforward technique is to publish my Android library on JitPack.io as a substitute.

Though it’s easy, I nonetheless spent my entire day to determine that out. It’s primarily as a result of tutorials on the market (even the official documentation) are lacking data and never beginner-friendly sufficient.

So, I will share the step-by-step guides on tips on how to do it and hopefully, this will prevent a variety of your time.

1. Create a New Venture

  • Go to File -> New -> New Venture…

  • Select both Empty Exercise or Empty Compose Exercise, click on Subsequent

  • Replace Title and Save Location

  • Click on End

How_to_Publish_Android Library_on_JitPack_01.gif

2. Create a New Module

  • Go to File -> New -> New Module…

  • Choose Android Library, replace Module Title and Package deal Title

  • Click on End

How_to_Publish_Android Library_on_JitPack_02.gif

3. Add Code Into Your Module

The module needs to be created within the root venture folder.

  • Go to the bundle, proper click on, choose New -> Kotlin Class/File

How_to_Publish_Android Library_on_JitPack_03.gif

  • Implement this code for instance
bundle com.vtsen.sydneysuburbs

object Sydney {
    val suburbs = listOf("Ryde", "Chippendale")
}

4. Use the Native Module

So as to use the module that you just simply created,

  • Add implementation venture(':<Module_Name>') dependency within the construct.gradle (app stage) file.

Groovy

dependencies {
    ...
    implementation venture(':SydneySuburbs')
}

Kotlin

dependencies {
    ...
    implementation(venture(":SydneySuburbs"))
}
  • Entry / use the code that you just created in step 3 above. E.g. Sydney.suburbs[0]
import com.vtsen.sydneysuburbs.Sydney
...
    
    Floor(colour = MaterialTheme.colours.background) {
        Greeting(Sydney.suburbs[0])
    }
...
  • Run your app, it ought to work!

5. Setup and Configure for JitPack.io

  • Add maven-publish plugin in construct.gradle file (Android library module stage).

Groovy

plugins {
    ...
    id 'maven-publish'
}

Kotlin

plugins {
    ...
    id("maven-publish")
}

Observe: There are 3 construct.gradle recordsdata – venture stage, app module stage and Android library module stage that you just simply created). Please be sure to replace the proper construct.gradle file.

  • Add afterEvaluate on the finish of the construct.gradle file (Android library module stage)

Groovy

publishing {
    publications {
        launch(MavenPublication) {
            groupId = 'com.github.vinchamp77'
            artifactId = 'demo-simple-android-lib'
            model = '0.0.0'

            afterEvaluate {
                from parts.launch
            }
        }
    }
}

Kotin

publishing {
    publications {
        register<MavenPublication>("launch") {
            groupId = "demo-simple-android-lib"
            artifactId = "demo-simple-android-lib"
            model = "0.0.3"

            afterEvaluate {
                from(parts["release"])
            }
        }
    }
}
  1. groupId = com.github.<Your_GitHub_User_Name>

  2. artifactId = '<Your_GitHub_Repository_Name>'

Confer with official Android documentation on tips on how to create the publication.

  • Swap to venture mode, add the jitpack.yml in venture root folder

How_to_Publish_Android Library_on_JitPack_04.gif

The content material in jitpack.yml:

jdk:
  - openjdk11

[Updated – Oct 15, 2022]: In the event you get the next warnings, chances are you’ll wish to replace the publising choices in your construct.gradle.

Software program Elements won’t be created robotically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the longer term habits, set the Gradle property android.disableAutomaticComponentCreation=true within the gradle.properties file or use the brand new publishing DSL.

Groovy & Kotlin

android {
    ...
    publishing {
        singleVariant("launch") {
            withSourcesJar()
            withJavadocJar()
        }
    }
    ...
}

6. Share Venture on GitHub

Now, it is able to add your tasks to the GitHub repository.

You too can clear up unused dependencies earlier than you add your venture to GitHub. This might help save the construct time when JitPack.io builds your venture.

  • Observe the detailed steps under if you do not know tips on how to do it
  • Please be sure the repository title matches the artifactId in step 5 and uncheck the personal examine field

How_to_Publish_Android Library_on_JitPack_05.png

7. Signal Up JitPack

  • Go to jitpack.io, click on the Signal In button on the high left

  • Authorize JitPack to permit JitPack entry to your GitHub account

How_to_Publish_Android Library_on_JitPack_06.png

  • Choose your repository and click on Look Up. You must see the next:

How_to_Publish_Android Library_on_JitPack_07.png

8. Create a New Launch to Set off JitPack Construct

  • Go to your repository, click on Releases on the proper (under the About).

  • Click on Draft a New Launch

  • Click on Selected a tag, and enter the identical model that you just specify in step 5 above

  • Press enter

  • Click on Publish launch

How_to_Publish_Android Library_on_JitPack_08.gif

9. Monitor JitPack Construct

  • Return to jitpack.io, and click on Look Up.

  • Look forward to some time, you need to see the Log icon is construct in progress.

How_to_Publish_Android Library_on_JitPack_09.png

  • When the construct is completed, you need to see one thing like this:

How_to_Publish_Android Library_on_JitPack_10.png

Observe: If the construct failed, you need to see the purple report. If it passes, you need to see the inexperienced report above.

  • Click on on the inexperienced report, you need to see one thing like this on the finish.

How_to_Publish_Android Library_on_JitPack_11.png

10. Import JitPack Android Library

As soon as the JitPack has efficiently constructed your Android library, it is able to import your Android library to your venture from JitPack.io.

Observe: I am utilizing the identical venture that I exploit to create this Android library for instance.

  • In settings.gradle, add maven { url 'https://jitpack.io' }

Groovy

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        maven { url 'https://jitpack.io' }
    }
}

Kotlin

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        maven ("https://jitpack.io")
    }
}

Observe: In the event you add this in construct.gradle (venture stage), it will not work. You have to add it within the settings.gradle as a substitute.

  • In construct.gradle (app stage), substitute implementation venture(':SydneySuburbs') with implementation 'com.github.<github_user_name>:<repository_name>:<version_name>'

Groovy

dependencies {
    ...
    implementation 'com.github.vinchamp77:demo-simple-android-lib:0.0.0'
}

Kotlin

dependencies {
    ...
    implementation ("com.github.vinchamp77:demo-simple-android-lib:0.0.0")
}
  • Now, your venture can import the Android library bundle and begin utilizing it. For instance:
import com.vtsen.sydneysuburbs.Sydney

Abstract

Some suggestions that I get from Twitter is a few individuals locally will not even contemplate your library if it is not on mavenCentral(). So it’s price contemplating publish to mavenCentral().

Effectively, I wish to, however when you have any easy-to-follow tutorials, please let me know. For studying and newbie functions, JitPack.io is sweet sufficient for me, at the least for now. It’s straightforward and easy to set it up.

Supply Code

GitHub repository: demo-simple-android-lib

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments