Today suddenly whim, want to toss about, let their library can be remote dependence. I found a lot of tutorials on the Internet, and I finally came out. Not much. To start the tutorial:
Sign up for a Bintray account
Bintray’s website :bintray.com
Personal registration address: bintray.com/signup/oss
You can also log in directly with your Github account. That’s how I am. But there’s one requirement: Your Github is tied to email and is available abroad (Gmail, Outlook, etc.).
2. Create a Maven repository
Not much said. Look at the picture speak
Once created, there will be another Maven
3. Project configuration.
1. Configure the root directory
Import all projects that have been uploaded and are open on GitHub.
Build. gradle in the root directory of the project is configured as follows
dependencies{
// Note: if this version is not 2.3.3, the following version may be invalid or error. You can change the version here or below. The error chicken solution is below
The classpath ‘com. Android. Tools. Build: gradle: 2.3.3’
// Add the following two lines.
Classpath ‘com. Making. Dcendents: android – maven – gradle – plugin: 1.5’
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
}
Error:
No service of type Factory available in ProjectScopeServices. Error resolution:
Code.google.com/p/android/i…
The link above requires climbing the wall to view. However, the version number does not match, so try to change the version several times.
Such as: the classpath ‘com. Android. View the build: gradle: 2.1.3’, then should be used
The classpath ‘com. Making. Dcendents: android – maven – gradle – the plugin: 1.4.1’, instead
Classpath ‘com. Making. Dcendents: android – maven – gradle – plugin: 1.5’
After modification, see the following figure:
2. Dependency configuration
Do the following configuration in build.gradle of your Library module (the module you want others to rely on remotely)
defaultConfig {
// Library does not have applicationId if there is a line to delete
minSdkVersion 8
targetSdkVersion 23
versionCode 1
VersionName ‘1.0.1’
}
And then at the bottom
dependencies {
compile fileTree(include: [‘*.jar’],dir:’libs’)
The compile ‘com. Android. Support: appcompat – v7:26.0.0-1’
The compile ‘com. Android. Support: appcompat – v7:26.0.0-1’
The compile ‘com. Android. Support: design: 26.0.0-1’
}
Add the following code below the above code:
/ / project reference version number, such as the compile ‘com. Yanzhenjie: andserver: 1.0.1 1.0.1 is here in the configuration.
Version = “0.1”
// Define two links, which will be used next.
// Project home page.
defsiteUrl =’https://github.com/JackiePenghe/BaseLibrary’
// Git repository url. (SSH connection must be used here)
defgitUrl =’[email protected]:JackiePenghe/BaseLibrary.git’
/ / the only package name, such as the compile ‘com. Yanzhenjie: andserver: 1.0.1 in com. Yanzhenjie is configured here. The only
group=”com.jackiepenghe”
install {
repositories.mavenInstaller{
// Generate pom.xml and parameters
pom {
project{
packaging’aar’
// The project description needs to be modified.
Name ‘BaseLibrary For Android’// Optional project name.
‘// Optional, project description.
Url siteUrl// Project home page, here is the reference defined above.
// Software open source protocol, now generally is Apache License2.0, copy my, do not need to modify.
licenses {
license {
Name ‘The Apache Software License, Version 2.0’
Url ‘http://www.apache.org/licenses/LICENSE-2.0.txt’
}
}
// Enter the basic information of the developer.
developers {
developer {
Id ‘jackiepenghe’// Developer ID.
Name ‘Jackiepenghe ‘// Developer name.
Email ‘[email protected]’// developer email.
}
}
// SCM, copy mine, no need to change here.
scm {
Connection gitUrl// Git repository address.
DeveloperConnection gitUrl// Git repository address.
Url siteUrl// Project home page.
}
}
}
}
}
// Generate jar package task, no need to modify.
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier=’sources’
}
// Generate jarDoc’s task without modification.
task javadoc(type: Javadoc) {
Options {// If the project contains Chinese, it is better to configure options. If there is no Chinese, do not include options
encoding”UTF-8″
charSet’UTF-8′
authortrue
versiontrue
links”http://docs.oracle.com/javase/7/docs/api”
}
source= android.sourceSets.main.java.srcDirs
classpath+=project.files(android.getBootClasspath().join(File.pathSeparator))
// destinationDir = file(“.. /javadoc/”)
// Ignore comment syntax errors, if using JDk1.8 your comments are not written properly, the compilation will fail. (If you have JDK1.9 installed on your PC and an error occurs after configuration, you must uninstall JDK1.9, remember)
failOnError false
}
// Generate javaDoc jar, no modification required.
task javadocJar(type: Jar,dependsOn: javadoc) {
classifier=’javadoc’
from javadoc.destinationDir
}
artifacts {
archivesjavadocJar
archivessourcesJar
}
// This is to read Bintray information. When we upload the project to Github, we will upload gradle files to it, so do not write account password information directly here.
Properties properties =newProperties()
properties.load(project.rootProject.file(‘local.properties’).newDataInputStream())
bintray {
User = properties.getProperty(“bintray.user”)// User name of bintray.
Key = properties.getProperty(“bintray. Apikey “)// Bintray just saved the APIKey.
configurations = [‘archives’]
pkg {
Repo =”maven”// Upload to maven library.
/ / release to Bintray project name, this is not the name of the compile ‘com. Yanzhenjie: andserver: 1.0.1 andserver. It’s the name of the Module in the project. Please see the illustration below for details
name =”baselibrary”
UserOrg =’jackiepenghe’ // Bintray user name.
websiteUrl = siteUrl
vcsUrl = gitUrl
Licenses = [” Apache 2.0 “]
Publish =true// Whether the project is public.
}
}
Here is the modified image:
You can clearly see that a file (local.properties) is referenced in the configuration. One final step: Open the local.properties file (in the project root directory)
Duplicate these two to go:
bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY
Replace YOUR_BINTRAY_USERNAME and YOUR_BINTRAY_API_KEY at the top with your own.
The acquisition method is shown as follows:
3. Upload projects for sharing (remote dependency)
Open the Android Studio command line:
As shown in figure:
Enter the command gradlew install
Wait for compilation to complete. BUILD SUCCESSFUL
Enter the command gradlew bintrayUpload
Wait for compilation to complete. BUILD SUCCESSFUL
Alternatively, instead of executing the above two commands, simply execute the following command:
gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
Remember to replace the user and key with your own, and also say BUILD SUCCESSFUL.
After successfully executing the above command, go to bintray.com/ and you will find another project in Maven.
Enter the maven. And you can see it’s done.
Enter the project (slow if you don’t climb the wall, just wait) and share the project with jCenter. This is the end of the tutorial.
And don’t forget to submit
After submission and waiting for approval, it can be relied upon for use
This is the end of the tutorial. Write an article for the first time, have imperfect place please put forward your valuable opinion