Android logo with SDK box, symbolizing code reuse and easy integration in Android Studio

Brytecore provides lead analytics to agents and companies in the real estate industry. They deliver their advanced machine intelligence directly to the point of contact with leads.

This means providing multiple solutions for integration with Brytecore's data collection and intelligence. Sometimes this is right on a website, but for larger companies, it might require native mobile libraries.

To help these clients, Brytecore needed a solution that was easy to integrate, and in the case of Android, easy to include within the application build process.

Android libraries can also be useful tools if you find yourself reusing code throughout your project - or across multiple projects. To use a published Android Library, you’ll need to upload it to a distribution center like Bintray. The following steps describe how to create an Android Library, upload it to Bintray, and publish it to JCenter.

1. Create an Android Library Project

To upload an Android Library to JCenter, you first need to make sure that the project is in the correct format. Your project must include an Android Library module containing the functionality of your library. To create an Android Library module, first, create a new project in Android Studio.

A screenshot of an Android Studio dialog window where an Android Developer would configure a new project.
Configure a New Project in Android Studio.
A screenshot of an Android Studio dialog window where an Android Developer would select their target SDK minimum version and maximum version.
Set the minimum SDK target for your target devices.
A screenshot of an Android Studio dialog window where an Android Developer would add an activity to their application project.
Add an activity.
A screenshot of an Android Studio dialog window where a Android Developer would customize the activity and give it a name.
Set the activity name.

Then add a new Android Library module.

A screenshot of a Android Studio with the File toolbar open so an Android Developer can create a new module.
Create a new module.
A screenshot of an Android Studio dialog window where an Android Developer would select Android Library.
Create a new Android Library module.
A screenshot of an Android Studio dialog window where an Android Developer would name their new library.
Configure the new module.

2. Create a Bintray Account and Package

Once the Android Library is created, and the desired functionality is inside the module, you are ready to proceed with the building process. If you don’t already have an account, sign up for a Bintray, and then create a new repository for Maven distributions.

A screenshot of the Bintray repository index where an Android Developer would see existing repositories or create a new one.
A screenshot of the Bintray we application where an Android Developer can create a new repository.

3. Edit Gradle Files and Upload to Bintray

To upload your Android Library files to Bintray, you’ll need to make some additions to your Gradle files and your local.properties file. Add the following to your project's build.gradle file:

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

dependencies {
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}

You’ll need your Bintray API key for the next step.

In your local.properties file, add your Bintray username and API key as follows:

## This file is automatically generated by Android Studio.
# Do not modify this file - YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle,
# For customization when using a Version Control System, please read the
# header note.
#Tue Jul 17 13:02:49 EDT 2018
ndk.dir=/Users/marisagomez/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/marisagomez/Library/Android/sdk 
bintray.user=<USERNAME> 
bintray.apikey=<API_KEY>

Once that’s complete, create two additional Gradle files called bintray.gradle and install.gradle.

A screenshot of an Android Studio dialog window where a Android Developer can create a new file so that they may add a bintray.gradle and install.gradle to their Android application project.
A screenshot of an Android Studio dialog window where a Android Developer would name their new file.

Add the following to your bintray.gradle file with your library's information:

apply plugin: 'com.jfrog.bintray'

version = '1.0.0'

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

Properties properties = new Properties()
properties.load( new FileInputStream("local.properties"))

// Bintray
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    pkg {
        repo = 'maven'
        name = 'com.example.androidlibrary
        configurations = ['archives']
        desc = 'An android library.'
        websiteUrl = 'https://github.com/cuttlesoft/android-library-example'
        vcsUrl = 'https://github.com/cuttlesoft/anroid-library-example.git'
        licenses = ["Apache-2.0"]
        publish = true
        publicDownloadNumbers = true
    }
}

Now add this to the install.gradle file, using the same process as above:

apply plugin: 'com.github.dcendents.android-maven'

group = 'com.example.androidlibrary'

install {
   repositories.mavenInstaller {
       pom {
           project {
               packaging 'aar'
               groupId 'com.example.androidlibrary'
               artifactId 'androidlibrary'
               name 'androidlibrary'
               description 'An android library.'
               url 'https://github.com/cuttlesoft/android-library-example'

               licenses {
                   license {
                       name 'The Apache Software License, Version 2.0'
                       url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                   }
               }

               developers {
                   developer {
                       id 'cuttlesoft'
                       name 'Marisa Gomez'
                       email 'marisa.gomez@cuttlesoft.com'
                   }
               }

               scm {
                   connection 'https://github.com/cuttlesoft/android-library-example.git'
                   developerConnection 'https://github.com/cuttlesoft/android-library-example.git'
                   url 'https://github.com/cuttlesoft/android-library-example'
               }
           }
       }
   }
}

Lastly, add the following to the bottom of your module’s build.gradle:

apply from: 'install.gradle'
apply from: 'bintray.gradle'

Now, you can run the following commands:
> ./gradlew install
> ./gradlew bintrayUpload

Once both commands finish successfully, refresh your Bintray account and you’ll see the new package.

A card from the Bintray website for a published library.

4. Publish to JCenter

Select the project, and under the Linked to section, you can select Add to JCenter.

Select the project, and under the linked to section, you can select Add to JCenter.

Fill out the comment, and hit Send.

You can now add your library to any project by including the JCenter link in the app’s build.gradle:

compile 'com.example.androidlibrary:androidlibrary:1.0.0'

There you have it! Now anyone can add your SDK to their project easily, letting you deliver better Android integrations for your customers, or contribute Android's open source community.

Related Posts

August 18, 2024 • Frank Valcarcel

What makes Enterprise Software Development Different?

Enterprise software powers large organizations, handling complex tasks across departments. From robust security to scalability, these solutions face unique challenges. Explore what makes software “enterprise-ready” and how to choose the right development approach for your business.

Cuttlesoft's leadership team in a software design and planning meeting at our Denver headquarters
December 21, 2019 • Frank Valcarcel

Cuttlesoft Ranked a 5-Star Agency!

Cuttlesoft achieves levels of flexibility and efficiency that set us apart from the competition. Which is why our 5-star ranking on Clutch, a premier B2B buying guide, shows we can deliver.