【问题标题】:How to deploy android library on gradle or google repositry?如何在 gradle 或 google 存储库中部署 android 库?
【发布时间】:2019-01-16 18:28:54
【问题描述】:

我想在 Gradle 上部署几个库(谷歌存储库等) 这样任何人都可以使用 Gradle 访问它,就像我们在 android studio app.gradle 文件中所做的那样

例如:实现 'io.reactivex.rxjava2:rxandroid:2.0.1'

我想知道部署的过程,我已经有了库。 谢谢

【问题讨论】:

    标签: android android-studio sdk android-gradle-plugin shared-libraries


    【解决方案1】:

    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'
    

    谢谢你:)

    【讨论】:

    • 感谢您的详细解释。
    【解决方案2】:

    你需要一个神器。您可以使用 maven-centraljitpack 等公开的,也可以使用 JFrog 创建自己的。

    然后更新您的库项目,使其能够与 maven 一起创建工件。 之后,您就可以发布了。

    如果您不熟悉 jitpack,我建议您使用它,因为它是一个庞大的主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2014-12-28
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多