我正在尝试编写一些 Android 库以在多个项目中重复使用。所以我希望能够将库存放在 repo 中,然后使用 gradle 导入它。我想要实现的一个例子是 Picasso lib。
https://github.com/square/picasso
要开始使用这个库,我唯一需要做的就是将这一行添加到我的应用程序 build.gradle 中:implementation 'com.squareup.picasso:picasso:2.71828'
有人可以为我指出引用或提供执行此操作的步骤吗?
提前致谢
最佳答案
您可以按照此步骤逐步上传 android 库。 Click here查看详细信息。 然后你可以添加到你的 build.gradle 文件中来使用它。
按照这个。
第 1 步:使用您的 GitHub/Google 帐户在 Bintray 中创建一个帐户 第 2 步:首先在您的 GitHub 中创建一个存储库。然后在 Bintray 中添加该存储库。 第 3 步:在 Android Studio 中打开您的库项目并将此行添加到您的 build.gradle 文件中:
classpath 'com.novoda:bintray-release:{latest_version}'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha07'
// Step I: add this line
classpath 'com.novoda:bintray-release:0.8.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
第四步:在/app目录下的build.gradle文件中添加项目详情
apply plugin: ‘com.android.library’
publish {
def groupProjectID = '{package_name}'
def artifactProjectID = '{name_of_your_library}'
def publishVersionID = 'library_version_code'
userOrg = '{username_of_bintray}'
repoName = 'repository_name'
groupId = groupProjectID
artifactId = artifactProjectID
publishVersion = publishVersionID
desc = '{library description}'
website = '{github_url}
}
//Step I: Add the below line
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'com.android.library'
//Step II: Add the below publish details
publish {
def groupProjectID = 'com.an.optimize'
def artifactProjectID = 'optimize'
def publishVersionID = '0.1.0'
userOrg = 'murthyanitaa'
repoName = 'Optimize'
groupId = groupProjectID
artifactId = artifactProjectID
publishVersion = publishVersionID
desc = 'Android library for displaying data based on JSON configuration fetched from server. With this library, you can kiss goodbye to string.xml, dimen.xml, arrays.xml. Keep all your string/integer/array config in one file. The library will automatically fetch the data from the url you provide.'
website = 'https://github.com/anitaa1990/Optimize'
}
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "android.arch.work:work-runtime:1.0.0-alpha01"
}
第 5 步:上传到 Bintray:在 Android Studio 的终端中,添加以下命令来清理、构建库并将其上传到 bintray:
gradle clean build bintrayUpload -PbintrayUser={userid_bintray} -PbintrayKey={apikey_bintray} -PdryRun=false
第 6 步:链接到 JCenter:在 Bintray 中的项目存储库下,您将看到您的库以及您指定的版本详细信息。现在您需要做的就是单击“添加到 JCenter”。
关于android - 如何设置 Android 库以使用 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56345816/