Personal blog: Haichenyi.com. Thank you for attention
The previous two articles covered how to generate jar packages, AAR packages, and how to use them. This article is about android Studio’s online dependencies — the JCenter repository. The default early AS dependencies were the Google and Maven repositories, that is, this location in our build.gradle file under our project directory:
allprojects {
repositories {
google()
jcenter()
}
}
Copy the code
Here we see the JCenter repository where Maven was replaced later.
In fact, the most important thing is how to configure the problem. All the other things I’ve talked about in a nutshell.
Step 1: You have to have a Bintray account. Go and sign up for one. You may see information about companies that need it. The registered address of the individual. I’m using @yeah.net from netease. You can register one from netease. Click me and change the suffix to yeah.net.
Step 2: Build a new warehouse. Log in to Bintray using the account password you just signed up for. Then, you will find the Add New Repository button on the left side of the screen. Click. You will see the following screen:
Name: The name of your warehouse. We’ll use it later when we submit
Type: Indicates the Maven type
-sheldon: Licenses. I said Apache-2.0
-Blair: Well, you can write a Description. You don’t have to write it
Then, click New. You don’t have to do anything else. Add Packages. Instead of adding packages, I use command Create.
Step 3: Find our API Key. And that’s what you’re going to use in your final submission. The diagram below:
Step 4: Create a new project, and create a new Library. (PS: The library name is still important. It is the name between the first colon and the second colon when you add the dependency, and it cannot be changed. For example: implementation ‘com. Android. Support: appcompat – v7:27.1.1’, it’s here appcompat – v7) write our library, and then begin to upload configuration information.
1. Add the following code to your build.gradle project:
dependencies {
classpath 'com. Android. Tools. Build: gradle: 3.0.0'// Add the following two sentences to configure classpath'com. Making. Dcendents: android - maven - gradle - plugin: 2.1'
classpath 'com. Jfrog. Bintray. Gradle: gradle bintray - plugin: 1.7.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Copy the code
2. Open library build.gradle. Add the following long code. I copied the build.gradle file from my own library directly here. I’ll comment it line by line, so you can read it.
// This one comes with it. This is a library, not an Application Apply plugin:'com.android.library'// Plugins are the same as the apply plugin in the first line:'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'Git project home page When I did it, it got stuck right here. I don't have one of these. It doesn't really do anything, it's like a relay connection, but it has to. How do we do that? You can create a repository on your Github and just throw the link in'https://github.com/haichenyi/MyUtils'Git def gitUrl = Git def gitUrl = Git def gitUrl ='https://github.com/haichenyi/MyUtils.git'// Write it as follows. Properties file and // our bintray.user and bintray.apikey. That's our account and apikey. No need to write a password. Properties properties = new Properties() properties.load(project.rootProject.file('local.properties'NewDataInputStream ()) // The final reference form, such as compile'com. Haichenyi. Aloe: utils: 1.0.0'// Utils is our library name. We cannot change version ="1.0.0"// Release version group ="com.haichenyi.aloe"Android {compileSdkVersion 27 // whatever name you want, I don't know what to use resourcePrefix"wz_"
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}} {implementation fileTree(implementation fileTree)}'libs', include: ['*.jar'])
implementation'com. Android. Support: appcompat - v7:27.1.1'
implementation 'com. Tbruyelle. Rxpermissions2: rxpermissions: 0.9.4 @ aar'
implementation 'the IO. Reactivex. Rxjava2: rxjava: 2.1.6'
implementation 'com. Squareup. Okhttp3: okhttp: 3.8.0'
implementation 'com. Google. Code. Gson: gson: 2.8.0'} bintray {// Here is the user and apikey user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
pkg {
repo = 'Utils'// The name of the repository you created is the same as the name of the repository you created on Bintray'MyUtils'WebsiteUrl = siteUrl vcsUrl = gitUrl websiteUrl = siteUrl vcsUrl = gitUrl websiteUrl = siteUrl vcsUrl = gitUrl'the Apache 2.0']// The license file must be selected during warehouse creationtype
// userOrg = 'mumusalibrary'// create the organization name publish =true// If the project is open, open others can refer to version {name ='1.0.0'// Version name = desc ='Utility class'// Release = new Date() vcsTag ='v1.0.0'
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
configurations = ['archives'} install {// install (); // install (); // install (); Don't have to change other repositories. MavenInstaller {/ / This generates POM. The XML with the proper parameters POM {project {packaging'aar'
// Add your description here
name 'xxx'// Project name description'XXX // Url siteUrl // Set your license licenses {license {name'Apache-2.0' //和之前自己定义的协议一致
url 'https://raw.githubusercontent.com/minggo620/Pluto-Android/master/LICENSE' } } developers { developer { id 'xxxxxx'// Fill in bintray or Github username, in this case I'm using my Github name'xx'// Name, I put in the nickname email on Bintray'xxxx'// email}} SCM {connection gitUrl developerConnection gitUrl url siteUrl}}}}} task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } task javadoc(type: Javadoc) {failOnError false / / must be added in order to avoid error 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 } javadoc { options { Encoding "UTF-8" charSet '; // Encoding "utF-8" charSet '; // Encoding "utF-8" charSet ';UTF-8' author true version true links "http://docs.oracle.com/javase/7/docs/api" } }Copy the code
Step 5: Upload
After the configuration is complete, upload JCenter to Android Studio Terminal
-
Gradlew assembleRelease Gradlew: XXX :assembleRelease gradlew: XXX :assembleRelease
-
Gradlew: XXX :install
-
Upload to JCenter repository: gradlew: XXX :bintrayUpload
Here XXX is the name of your library. And then you’ll notice that under the repository that your Bintray created, there’s a package. When you click on your package, you will find the following image:
I added it, you should say Add to JCenter, you hit send on the new page. Submit for review. Just be patient. As soon as half an hour, as slow as 1 to 2 days.