为了使用Android Studio开发Android应用程序,我们通常会在build.gralde
中添加依赖项,而不是添加jar或库。下面给出的例子
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.2.1'
如何在Android Studio中创建自己的gradle依赖库?
答案 0 :(得分:4)
我已经创建了自己的库CustomSpinner
及其Gradle的依赖项
是
dependencies {
compile 'com.github.piotrek1543:CustomSpinner:0.1'
}
我非常确定这是你所期待的。
我是使用Jitpack.io并按照这篇伟大的中篇文章中的步骤进行的:
Create and Distribute your own Android Library after reading this post!
我不想复制粘贴已经说过的内容,所以请耐心地阅读这篇文章。
希望它会有所帮助
答案 1 :(得分:1)
您必须制作Android库(新项目 - > Android库项目),然后将其上传到bintray。
答案 2 :(得分:1)
JitPack对此非常了不起。你可以非常简单地将你创建的库提供给任何人,如果它是在GitHub(或其他git主机)上托管的,你可以添加Gradle和JitPack想要的一些配置。在JitPack发布文档中查看here。
答案 3 :(得分:1)
您可以在项目中使用不同类型的依赖项:
dependencies {
// Dependency on the "mylibrary" module from this project
compile project(":mylibrary")
// Remote binary dependency
compile 'com.android.support:appcompat-v7:24.1.0'
// Local binary dependency
compile fileTree(dir: 'libs', include: ['*.jar'])
}
您也可以使用定义flatDir
:
repositories {
flatDir {
dirs 'libs'
}
}
然后添加依赖项:
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
要创建库模块,只需在Android Studio中创建一个模块,然后在module/build.gradle
apply plugin: 'com.android.library'
然后您可以将其用作:
compile project(":mylibrary")
)