Android Studio创建远程仓库
将Android代码托管到GitHub上后,可通过JitPack创建一个远程的Android依赖库,通过compile ‘……’即可使用,看一下具体步骤。
首先打开Android Studio创建一个Android工程,选择工程右键选择new -> modle选择==Android Library==点击下一步即可,如下图:
然后在工程的build.gradle下添加如下代码:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
在library的build.gradle配置github账户信息:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourName'
配置玩点击Sync Now即可。
使用本地库,在工程中创建本地依赖:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':mylibrary')
}
这样就可以调用mylibrary库中的类和方法了,当然也可以调用xml资源和图片。
到这里本地库就创建完成了,现在把它托管到Github,如下图,是我托管后的项目
托管完成后点击release,添加版本号、版本名、简要说明:
版本发布后:
发布后复制项目地址:
打开JitPack官网,输入复制的设置,点击Look up,选择发布的版本,点击Get it即建立远程仓库:
使用的时候和正常的依赖库用法一样,这里就不多说了。
参考网站:
https://developer.android.com/studio/projects/android-library.html?hl=zh-cn
https://developer.android.com/studio/build/dependencies.html#remote-repositories