1.在Android Studio中制作库模块 [假设你已经准备好了]
2。在 Bintray 上创建空间
使用您的确切模块名称和您的 GitHub 存储库链接填写所需信息,如下所示,然后单击“创建包”。
恭喜!您已成功完成第二步。
3.在 Bintray 和 JCenter 上上传您的库
现在您需要配置您的库,以便您可以将其上传到 Bintray,然后再上传到 JCenter。
通过添加以下依赖项来修改项目 build.gradle 文件:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
在 local.properties 文件中添加您的 Bintray 身份验证详细信息。该信息不应推送到版本控制系统。
bintray.user=“你的用户名”
bintray.apikey=“你的 API 密钥”
您可以按照以下步骤在您的帐户中找到这两个凭据 -
打开您的 Bintray 帐户,单击您的姓名,然后单击您的姓名下的编辑,然后单击 API Key 选项卡。
现在我们需要修改我们的模块 build.gradle 文件。打开文件,按照以下步骤进行修改。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
ext {
bintrayRepo = 'Utility' // your repo name
bintrayName = 'time-utils' // has to be same as your library module name
publishedGroupId = 'com.timeutility' // your module package name
libraryName = ‘time-utils’
artifact = 'time-utils' // has to be same as your library module name
libraryDescription = 'A set of methods used to manipulate time object'
siteUrl = 'https://github.com/androidCode/time-utils'
gitUrl = 'https://github.com/androidCode/time-utils.git'
libraryVersion = '1.0'
developerId = ‘sachit’
developerName = Sachit
developerEmail = 'sachit.wadhawan@quovantis.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
android {
// -------- your target version and all required configuration. These are normal as for other projects and generate by android studio itself
}
dependencies {
// Your dependecies
}
// add it to the bottom of the file
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
同步项目。配置完所有内容后,在终端中的项目根目录中运行以下命令。
./gradlew clean build install bintrayUpload
欢呼万岁!如果它显示 BUILD SUCCESSFUL。
在 Bintray Web 界面中检查您的包。您将在版本区域中看到更改。现在需要将其推送到 JCenter。现在,一旦您的项目在 Bintray 上启动,只需点击“添加到 JCenter”按钮即可与 JCenter 同步。
您的请求可能需要几个小时才能被接受。发生这种情况时,您应该会通过电子邮件收到通知,并且还会在“链接到”部分下的包详细信息中看到 jCenter 徽章。
恭喜!你的图书馆现在在 jCenter 上!!!您现在可以将 gradle 路径添加到您的项目中。例如我的依赖是这样的:
implementation 'xxxxxxxxxx:xxxxxx:1.0'
谢谢你:)