This article is launched on the wechat public account “AndroidTraveler”.

background

In fact, Android uploading open source projects to JCenter is not a new thing, and there are many articles online.

I refer to some of these articles myself when uploading open source projects to JCenter.

However, due to versioning and environmental issues, many articles written long ago are not fully applicable.

Based on this, here is a summary of the recent open source project I uploaded to jCenter.

The uploaded open source project is an Android 6.0 dynamic permission application project.

Based on the single responsibility principle of software, I won’t go into that here.

This article mainly discusses the way to upload the open source project to jCenter. If necessary, I will write another article to introduce the open source project.

The development environment

Android Studio version: 3.2.1 Java Version: 1.8.0_45

The road to the pit

1. Make the project run

Since I wrote this open source project two and a half years ago, I need to make sure that the project I pull can run properly first.

Sure enough, the console outputs the following message

No toolchains found in the NDK toolchains folder for ABI with prefix: mipsel-linux-android
Copy the code

It could have run before. Looks like it’s a problem with the AndroidStudio update.

The solution here is to upgrade gradle.

Will the original

classpath 'com. Android. Tools. Build: gradle: 2.2.2'
Copy the code

Upgrade to

classpath 'com. Android. Tools. Build: gradle: 3.2.1'
Copy the code

Then adjust the others accordingly, and the project can run normally on the equipment.

2. Separate the open source project to be uploaded into a Module

Previous open source projects put all the code in the App Module.

Other partners need to copy the relevant folders into their own projects before using them.

The Module extraction here does something similar: it migrates related files to the new Module to be uploaded.

3. Create a bintray.com account

To upload open source projects to JCenter, we need to have an account first.

You think creating an account is easy?

There are still a lot of holes in it. Let me tell you all about it.

Bintray.com/.

Click in and the first hole comes.

As shown, individual developers click to the right. Don’t click the button on the left because it’s brightly colored and has the word FREE.

Because START YOUR FREE TRIAL means to START YOUR FREE TRIAL, and the TRIAL instructions have a period of time, so you get the idea.

Click on the right to enter the registration interface.

For convenience, I used a third party login.

At first I hit Sign up with Github.

After filling in the information, I clicked “Complete registration”, but there was no reaction on the interface.

Finally found QQ mailbox relationship.

Later, I clicked Sign up with Google, and the account was successfully created.

So the second pitfall is to register your email or use a third party to register your email with a Gmail account.

The conclusion of the pro test here is that QQ mailbox can not, Gmail mailbox can. I don’t know about the other mailboxes.

This is the second pit for registering an account.

4. Create a Maven repository

Once logged in to the home page, click Add New Repository.

The first and second are required. Enter maven for Name and Maven for Type.

If there is no action in this step, an error will be reported at the end of the upload.

5. Introduce the bintray – release

Add the following statement to the Dependencies block of your project’s build.gradle file:

classpath 'com. Novoda: bintray - release: 0.9.1'
Copy the code

Add the following statement to build.gradle of the Module you want to upload:

At the top of the file add:

apply plugin: 'com.novoda.bintray-release'
Copy the code

At the end of the file add:

publish {
    userOrg = 'zengyuzhan'//bintray.com user name groupId ='com.zengyu'// unique ID, one of the components of the last dependent library name artifactId ='permission'// Repository name publishVersion ='1.0.0'// Version desc ='for android dynamic request permission'// describe website ='https://github.com/nesger/PermissionManager'// Open source project url}Copy the code

After publish writing, rely on is the introduction of the implementation behind the ‘groupId: artifactId: publishVersion’

So here’s an example

implementation 'com. Zengyu: permission: 1.0.0'
Copy the code

There are some bugs in this step, such as the introduction of classpath. Here, WHEN I introduced version 0.8.1, I reported the following error:

Cause: com.novoda.gradle.release.AndroidLibrary$LibraryUsage.getDependencyConstraints()Ljava/util/Set;
Copy the code

An error is reported when the imported version is 0.6.1:

No such property: FOR_RUNTIME for class: org.gradle.api.attributes.Usage
Copy the code

If the imported version is 0.3.4, an error is reported:

Unable to load class 'org.gradle.api.internal.component.Usage'.
Copy the code

Change to the latest version of 0.9.1 and you will be fine. So assuming that when you see this article, go to GitHub to see if the latest version is 0.9.1.

GitHub website: github.com/novoda/bint…

6. Upload the open source library

Run the upload command in the project root directory and directly enter the command in the Terminal panel of Android Studio.

./gradlew clean build bintrayUpload -PbintrayUser=zengyuzhan -PbintrayKey=xxxxxx -PdryRun=false
Copy the code

PbintrayUser specifies the username of your bintray.com account. PbintrayKey specifies the API Key for your bintray.com website.

Obtain the API Key according to the following figure:

Click the copy button to copy to the clipboard, paste if needed.

After Terminal builds successfully, BUILD SUCCESSFUL is displayed.

An error occurred while compiling here, as follows:

Execution failed for task ':permission:javadocRelease'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): 
Copy the code

This is the Javadoc task error, I don’t need this, so the solution is to perform the task: not permission: javadocRelease.

In the allProjects statement block of your project’s build.gradle file, add the following statement:

tasks.getByPath(":permission:javadocRelease").enabled = false
Copy the code

You can see the error task in parentheses.

If your Javadoc error task is not the same as mine (most likely, depending on the Module name), then you need to fix it.

After the addition, the Sync project will be reported again without this problem.

7. Add to JCenter

Once the upload is complete, we need to go to Bintray.com and click Add to JCenter and wait for approval.

Since THE above project has been successfully published and clicked, I use another open source library to demonstrate this step.

To go to the home page, click Maven:

You can see all the package names you open source:

Click on the latest uploaded library that has not yet been added to Jcenter.

Click Go to Old Look

You can see the Add to JCenter button. Click on the

Simply write down a description of the library.

Click Send and the page will display a prompt. Then just wait for the email notification.

When you come in, you won’t see the Add to JCenter button.

For example, the library I approved earlier:

You can then refer to your project as you would any other tripartite library.

The summary is as follows:

The repository demonstrated in this article is: github.com/nesger/Perm…

Have not clear can leave a message or directly view my demo warehouse submission records and source code.

Reference links: blog.csdn.net/lmj62356579… www.jianshu.com/p/6f808c29e… Blog.csdn.net/anydrew/art…