以前我自己整理的工具类会打一个jar包,然后到处复制。自从IDE换到AS后,使用gradle导入其他工程,只要简单的一行代码,甚至还有界面化搜索功能,实在是好用的很,所以最近整理了一些工具类就想做成这种方式。于是查了些资料得知,JCenter现在是Android Studio中repositories的默认节点,所以要把项目上传到JCenter这个远端仓库,https://bintray.com/网站管理着JCenter仓库。
由于上传项目时,遇到了一些小问题,我根据网上的资料,整理一下这个过程。
配置Gradle
Module的build.gradle:
apply plugin: 'com.android.library' //把application改成library
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
//applicationId "包名" //需要注释掉applicationId,因为在rebuild的时候报错,具体原因可能是因为第一行改成library的原因,不是很清楚。
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7