在上一篇文章中,我提到了如何创建开放源代码android库 。 在本文中,我们将介绍如何将Android库发布到Bintray。 您的图书馆在Bintray上发布后,就可以通过gradle使用了。
从Bintray上发布图书馆基本上有5个步骤:
- 在https://bintray.com/上创建一个开源/付费帐户
- 在Bintray上创建您的存储库。
- 在Android Studio上安装bintray插件。
- 将库上传到Bintray。
- 提交该库以供最终发布。
1.在
如果您没有开源帐户或未付款,则无法在Bintray上发布图书馆。
使用开放源帐户,您的库将公开可用。 如果您希望包裹是私人的,请注册一个付费帐户。 他们有专业版和企业版。
由于我们正在谈论发布开源库,因此我们将在此处创建一个开源帐户。
按照简单的步骤创建您的帐户,然后通过确认邮件将其激活。 创建帐户后,请登录并继续进行下一步。
2.创建一个存储库。
让我们继续为我们的android库创建一个存储库。 如您所见,我已经创建了一个用于脉动按钮的按钮。
继续并输入存储库的所有详细信息。 对于库类型,选择maven。 对于许可证,我认为Apache 2.0许可证效果很好。
填写完表格后,继续并点击创建 。
3.在Android Studio上安装Bintray插件
使用novoda / bintray-release插件,创建和发布库非常容易。 让我们继续设置此插件。
- 首先,转到您的项目级别的 build.gradle文件,并为classpath添加以下行:
classpath 'com.novoda:bintray-release:<latest-version>'
请记住用最新版本的插件替换<latest-version>。 截至撰写本文时,最新版本为0.9.2。
- 接下来,转到您的应用程序级别 build.gradle文件,并将此行添加到顶部
apply plugin: 'com.novoda.bintray-release'
然后继续并同步项目。 我们终于设置了bintray插件。 现在,我们准备将我们的库上传到Bintray。
4.将库上传到Bintray。
要将我们的android库上传到bintray,我们需要在应用程序级别的 build.gradle文件中添加一些配置/凭据。 这就是我的build.gradle看起来像PulsatingButton的样子。
apply plugin: 'com.novoda.bintray-release' apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' //Step II: Add the below publish details publish {
def groupProjectID = 'com.ayusch.pulsatingbutton' def groupProjectID = 'com.ayusch.pulsatingbutton'
def artifactProjectID = 'pulsatingbutton'
def publishVersionID = '1.1.1'
userOrg = 'androidville'
repoName = 'PulsatingButton'
groupId = groupProjectID
artifactId = artifactProjectID
publishVersion = publishVersionID
desc = 'Android library to display a pulsating (growing & shrinking) button'
website = ' https://github.com/Ayusch/PulsatingButtonAndroidLibrary ' } android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile( 'proguard-android-optimize.txt' ), 'proguard-rules.pro'
}
} } dependencies {
implementation fileTree(dir: 'libs' , include: [ '*.jar' ])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
注意发布块。 这是插件将Android库上传到Bintray所必需的。所有凭据非常简单,您可以在Bintray帐户中找到它们。
最后,我们需要做的就是运行一个Android Studio命令来上传我们的库。
./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun= false
您可以在Bintray帐户的右上角找到bintray用户名。 要找到您的Bintray密钥,请转到:右上角(您的用户名)->编辑配置文件-> API密钥并复制您的api密钥。
将BINTRAY_KEY替换为API密钥,将BINTRAY_USERNAME替换为您的用户名。 然后在Android Studio上打开终端并粘贴并运行此命令。 等待它成功完成。 构建完成后,您的库将被上传到Bintray ,我们只需要提交它以进行最终审查。
5.提交库进行审查
在此最后步骤中,我们需要将库提交给JCenter进行最终审核,该发布将发布我们的Android库。
转到您的存储库->单击您的包,然后在“链接到”部分的右下角,您将看到一个提交到JCenter的选项。
单击添加到JCenter ,您将被重定向到一个表单,您需要在其中添加有关项目的信息。 然后最后单击提交。
在JCenter上审核和发布项目通常需要24小时。 您会通过邮件收到您的Android库已发布的确认消息。
现在,您可以使用Gradle将您的库包含到任何项目中了!
翻译自: https://www.javacodegeeks.com/2019/12/publishing-your-android-library-to-bintray-gradle.html