I'm working on creating a log-in screen to be used with multiple different android applications. What would be the best way to package it so that other people could use my log-in function on their apps. It would be preferred that it would auto-sync for them in-case we were to make changes. ***EDIT**** It seems packaging it into a library module is the best option. How does one go about uploading this module so that if we make an update to this module it will seamlessly update without having to pull from github for example.
我正在创建一个登录屏幕,用于多个不同的Android应用程序。打包它的最佳方法是什么,以便其他人可以在他们的应用程序上使用我的登录功能。如果我们要进行更改,最好是自动同步它们。 ***编辑****似乎将它打包成库模块是最好的选择。如何上传这个模块,这样如果我们对这个模块进行更新,它将无缝更新,而不必从github中取出。
Thanks!
谢谢!
5 个解决方案
#1
17
If you've pushed your code to GitHub then sharing the library (aar) is easy with JitPack.
如果您已将代码推送到GitHub,那么使用JitPack可以轻松共享库(aar)。
Your users will just need to add the repository to their build.gradle:
您的用户只需要将存储库添加到他们的build.gradle:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
and then your GitHub repository as dependency:
然后你的GitHub存储库作为依赖:
dependencies {
// ...
compile 'com.github.YourUsername:Repo:Release'
}
The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.
好消息是你不必上传你的图书馆。在幕后,JitPack将检查GitHub中的代码并进行编译。当您在GitHub上发布新版本时,其他人可以使用它。
There is also a guide on how to prepare an Android project.
还有一个关于如何准备Android项目的指南。
#2
5
Make the relevant classes into a library module - you already seem to know how to do that - and then use the Gradle Bintray plugin to upload it to JCenter.
将相关的类放入库模块 - 您似乎已经知道如何操作 - 然后使用Gradle Bintray插件将其上载到JCenter。
Let's say you set group
in build.gradle to com.ryan-newsom, version
to 1.0 and the project name is android-log-in-screen.
假设您将build.gradle中的group设置为com.ryan-newsom,版本设置为1.0,项目名称为android-log-in-screen。
(part of) android-log-in-screen/build.gradle:
(部分)android-log-in-screen / build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6"
}
}
apply plugin: 'com.jfrog.bintray'
group = 'com.ryan-newsom'
version = '1.0'
bintray {
// Omitted for brevity, refer to the examples on GitHub.
}
You (or anyone else) can then use it in your project by adding the following:
然后,您(或其他任何人)可以通过添加以下内容在项目中使用它:
(part of) other-project/build.gradle:
(part)other-project / build.gradle:
repositories {
jcenter()
}
dependencies {
compile "com.ryan-newsom:android-log-in-screen:1.0"
}
The library will then be pulled from JCenter and added to the classpath.
然后,库将从JCenter中提取并添加到类路径中。
#3
3
You can package the library into an AAR format. It will also contain the resources you used in your login module. After that you can push the AAR library format to bintray (which is free, and allows you to setup your own repository).
您可以将库打包为AAR格式。它还将包含您在登录模块中使用的资源。之后,您可以将AAR库格式推送到bintray(这是免费的,并允许您设置自己的存储库)。
Your collaborators can then access the library using a dependency that looks like:
然后,您的协作者可以使用类似于以下内容的依赖项访问库:
compile 'com.newsom:awesome-login-screen:0.5'
编译'com.newsom:awesome-login-screen:0.5'
Check this starter tutorial if you are using AndroidStudio/Gradle and would like to push it to bintray. https://github.com/jimcoven/android-bintray-kit
如果您使用的是AndroidStudio / Gradle,请查看此入门教程,并希望将其推送到bintray。 https://github.com/jimcoven/android-bintray-kit
#4
2
The best way to create a lib and make it available to other developers is creating a AAR so that developers can import it in their project using dependencies.
创建lib并将其提供给其他开发人员的最佳方法是创建AAR,以便开发人员可以使用依赖项在项目中导入它。
The process is quite long. These are the main steps you should follow to publish your lib:
这个过程很漫长。这些是您发布lib时应遵循的主要步骤:
- Register an account and create a new ticket (https://issues.sonatype.org)
- 注册一个帐户并创建一个新票证(https://issues.sonatype.org)
- Download (if you use OS X) GPGTools (http://www.gpgtools.org/)
- 下载(如果您使用OS X)GPGTools(http://www.gpgtools.org/)
- Modify project gradle files
- 修改项目gradle文件
- Create signing key Build
- 创建签名密钥Build
- sign and publish your files to the Staging repository
- 签名并将文件发布到Staging存储库
I wrote a post about it and to have more details you can look here. This is a piece of gradle file called maven_push.gradle:
我写了一篇关于它的帖子,并有更多细节,你可以在这里看看。这是一个名为maven_push.gradle的gradle文件:
apply plugin: 'maven'
apply plugin: 'signing'
def sonatypeRepositoryUrl
if (isReleaseBuild()) {
println 'RELEASE BUILD
sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
println 'SNAPSHOT BUILD'
sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('nexusUsername') ? nexusUsername : ""
}
def getRepositoryPassword() {
return hasProperty('nexusPassword') ? nexusPassword : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.artifactId = POM_ARTIFACT_ID
repository(url: sonatypeRepositoryUrl) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.allJava
classpath += project.files(android.plugin.getRuntimeJarList().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
//basename = artifact_id
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
//basename = artifact_id
from android.sourceSets.main.allSource
}
artifacts {
//archives packageReleaseJar
archives androidSourcesJar
archives androidJavadocsJar
}
}
while gradle.properties is:
而gradle.properties是:
VERSION_NAME=
VERSION_CODE=1
GROUP=
POM_DESCRIPTION=
POM_URL=
POM_SCM_URL= POM_SCM_CONNECTION=
POM_SCM_DEV_CONNECTION=scm:git@github.com:
POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=
POM_DEVELOPER_NAME=
There is another way but i did not try it and it seems to be easier. Give a look at jitpack.
还有另一种方法,但我没有尝试它,它似乎更容易。看看jitpack。
Hope it helps you.
希望它能帮到你。
#5
1
make the package or jar depending on your source, and post it on git hub the you can refer to the git from your ide to import or check for updates.
根据你的来源制作包或jar,并将它发布在git hub上,你可以参考你的ide中的git导入或检查更新。
#1
17
If you've pushed your code to GitHub then sharing the library (aar) is easy with JitPack.
如果您已将代码推送到GitHub,那么使用JitPack可以轻松共享库(aar)。
Your users will just need to add the repository to their build.gradle:
您的用户只需要将存储库添加到他们的build.gradle:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
and then your GitHub repository as dependency:
然后你的GitHub存储库作为依赖:
dependencies {
// ...
compile 'com.github.YourUsername:Repo:Release'
}
The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.
好消息是你不必上传你的图书馆。在幕后,JitPack将检查GitHub中的代码并进行编译。当您在GitHub上发布新版本时,其他人可以使用它。
There is also a guide on how to prepare an Android project.
还有一个关于如何准备Android项目的指南。
#2
5
Make the relevant classes into a library module - you already seem to know how to do that - and then use the Gradle Bintray plugin to upload it to JCenter.
将相关的类放入库模块 - 您似乎已经知道如何操作 - 然后使用Gradle Bintray插件将其上载到JCenter。
Let's say you set group
in build.gradle to com.ryan-newsom, version
to 1.0 and the project name is android-log-in-screen.
假设您将build.gradle中的group设置为com.ryan-newsom,版本设置为1.0,项目名称为android-log-in-screen。
(part of) android-log-in-screen/build.gradle:
(部分)android-log-in-screen / build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6"
}
}
apply plugin: 'com.jfrog.bintray'
group = 'com.ryan-newsom'
version = '1.0'
bintray {
// Omitted for brevity, refer to the examples on GitHub.
}
You (or anyone else) can then use it in your project by adding the following:
然后,您(或其他任何人)可以通过添加以下内容在项目中使用它:
(part of) other-project/build.gradle:
(part)other-project / build.gradle:
repositories {
jcenter()
}
dependencies {
compile "com.ryan-newsom:android-log-in-screen:1.0"
}
The library will then be pulled from JCenter and added to the classpath.
然后,库将从JCenter中提取并添加到类路径中。
#3
3
You can package the library into an AAR format. It will also contain the resources you used in your login module. After that you can push the AAR library format to bintray (which is free, and allows you to setup your own repository).
您可以将库打包为AAR格式。它还将包含您在登录模块中使用的资源。之后,您可以将AAR库格式推送到bintray(这是免费的,并允许您设置自己的存储库)。
Your collaborators can then access the library using a dependency that looks like:
然后,您的协作者可以使用类似于以下内容的依赖项访问库:
compile 'com.newsom:awesome-login-screen:0.5'
编译'com.newsom:awesome-login-screen:0.5'
Check this starter tutorial if you are using AndroidStudio/Gradle and would like to push it to bintray. https://github.com/jimcoven/android-bintray-kit
如果您使用的是AndroidStudio / Gradle,请查看此入门教程,并希望将其推送到bintray。 https://github.com/jimcoven/android-bintray-kit
#4
2
The best way to create a lib and make it available to other developers is creating a AAR so that developers can import it in their project using dependencies.
创建lib并将其提供给其他开发人员的最佳方法是创建AAR,以便开发人员可以使用依赖项在项目中导入它。
The process is quite long. These are the main steps you should follow to publish your lib:
这个过程很漫长。这些是您发布lib时应遵循的主要步骤:
- Register an account and create a new ticket (https://issues.sonatype.org)
- 注册一个帐户并创建一个新票证(https://issues.sonatype.org)
- Download (if you use OS X) GPGTools (http://www.gpgtools.org/)
- 下载(如果您使用OS X)GPGTools(http://www.gpgtools.org/)
- Modify project gradle files
- 修改项目gradle文件
- Create signing key Build
- 创建签名密钥Build
- sign and publish your files to the Staging repository
- 签名并将文件发布到Staging存储库
I wrote a post about it and to have more details you can look here. This is a piece of gradle file called maven_push.gradle:
我写了一篇关于它的帖子,并有更多细节,你可以在这里看看。这是一个名为maven_push.gradle的gradle文件:
apply plugin: 'maven'
apply plugin: 'signing'
def sonatypeRepositoryUrl
if (isReleaseBuild()) {
println 'RELEASE BUILD
sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
println 'SNAPSHOT BUILD'
sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('nexusUsername') ? nexusUsername : ""
}
def getRepositoryPassword() {
return hasProperty('nexusPassword') ? nexusPassword : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.artifactId = POM_ARTIFACT_ID
repository(url: sonatypeRepositoryUrl) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.allJava
classpath += project.files(android.plugin.getRuntimeJarList().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
//basename = artifact_id
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
//basename = artifact_id
from android.sourceSets.main.allSource
}
artifacts {
//archives packageReleaseJar
archives androidSourcesJar
archives androidJavadocsJar
}
}
while gradle.properties is:
而gradle.properties是:
VERSION_NAME=
VERSION_CODE=1
GROUP=
POM_DESCRIPTION=
POM_URL=
POM_SCM_URL= POM_SCM_CONNECTION=
POM_SCM_DEV_CONNECTION=scm:git@github.com:
POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=
POM_DEVELOPER_NAME=
There is another way but i did not try it and it seems to be easier. Give a look at jitpack.
还有另一种方法,但我没有尝试它,它似乎更容易。看看jitpack。
Hope it helps you.
希望它能帮到你。
#5
1
make the package or jar depending on your source, and post it on git hub the you can refer to the git from your ide to import or check for updates.
根据你的来源制作包或jar,并将它发布在git hub上,你可以参考你的ide中的git导入或检查更新。