9

Make an Android custom view and publish it. (Part 2)

 3 years ago
source link: https://enginebai.com/2018/05/11/publish-android-custom-view/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

In this part, I will demostrate how to publish the custom view so that other developers can use it by just simply adding dependency like this:

dependencies {
    ...
    compile 'com.dualcores.swagpoints:swagpoints:1.0.2'
}

Here we go:

1. Sign in/Register at distribution service.

Here what I used for distribution service is JFrog Bintray. Register a account if you don’t have. I will use Bintray as example, the UI may be different when you see this post!!

1_l76C89EMa-iduZXxKRIwCQ.png

2. Go to profile page to create a repository, package and version:

The repository is the place to host your several projects. You can choose any repository name whatever you what, it doesn’t matter for other developer.

螢幕快照 2016-11-26 下午10.59.45

Inside the new repository, you can create a package, that is the place to host your project. You can import your projects from Github.

螢幕快照 2016-11-26 下午11.05.54

For each package, you can create several versions, again, you can choose whatever name you want, not restricted to the traditional version number major.minor.patch rule.

螢幕快照 2016-11-27 上午8.45.54

3. Generate and upload aar files:

We use gradle to do this job, here I use this library to help https://github.com/blundell/release-android-library

Open you library module gradle file, add the following code snippet to buttom of module build.gradle file:

// or use the remote copy to keep update with latest changes

and JCenter configuration:

ext {
    PUBLISH_GROUP_ID = 'com.dualcores.swagpoints'
    PUBLISH_ARTIFACT_ID = 'swagpoints'
    PUBLISH_VERSION = '1.0.0'
}
螢幕快照 2016-11-27 上午9.02.37
The two place you have to insert code in library module build.gradle file

Then sync your project and open your terminal, go to your project root path, execute the command:

./gradlew clean build generateRelease

If success, you will see the result in you terminal and you can upload the zip file from PROJECT_ROOT/library/build/release/1.0.0:

螢幕快照 2016-11-27 上午9.12.13

4. Add to JCenter:

Go back to your project page in bintray, there will be a Add to JCenter button in right-hand column, just click it to fill out a message and wait to be accepted. It takes hours or several days to be accepted, just be patient. This step is required so that to make your project downloadable and discoverable by gradle dependencies.

螢幕快照 2016-11-27 上午9.20.19

5. Wait for acception and test it.

You will receive an email to inform you that your Add to JCenter request is accepted.

螢幕快照 2016-11-27 上午9.29.57

Once it is accepted, test if gradle dependency works well by adding the dependency to sample module and sync. If it builds successfully, congratulation!!!! You’ve done. Good job~

compile 'com.dualcores.swagpoints:swagpoints:1.0.0'

The version may change when you try to use it, just check my Github to get the latest version and give the project a star.

graphic

Happy coding!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK