我最近决定将我的 android 项目从 ant 切换到 gradle 构建系统。手动管理我们团队成员之间的库和模块依赖关系很快变得太多了。
一切开始顺利。我创建了一个新的 gradle 项目,移动了我的源和资源,并摆脱了我们在 /libs
文件夹周围挂起的所有主要第三方库 .jars,以便我可以利用新的 gradle maven 中央依赖项。那里没有问题。
现在我正试图找到一种好方法来设置对一些不在 maven central 上的不太流行的模块的依赖关系。我使用了一些我已经变得依赖的小型 android 模块(例如表单验证器、帮助程序 util 模块等)。问题是这些模块不仅仅是 .jars,还有资源。据我所知,我不能只将这些模块放在我的 /libs
文件夹中,然后让 gradle 为它们设置依赖项。我已经阅读了一些 .aar 文件,正在寻找一些建议,看看它们是否能解决我的问题,或者我忽略了一些简单的事情。下面是我当前的目录结构(带有一些注释)和我的 gradle.build
。
目录结构
/<project-directory>
/build
/gradle
/<application-directory>
/build
/src
/libs <-- where I would expect to put non-maven modules
/Form-Validator <-- MyApplication depends on this module
/build.gradle
/src
/java
/res
... etc etc etc
/Other-Module
/build.gradle (seen below)
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.2'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.#####.############"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'com.squareup.okio:okio:1.1.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.github.bumptech.glide:glide:3.4.0'
}
最佳答案
您可以将本地 Maven 存储库添加到您的 build.gradle 中:
repositories {
jcenter()
mavenCentral()
mavenLocal()
flatDir {
dirs 'libs'
}
}
本地存储库的位置取决于操作系统。在Linux中它是 $HOME/.m2/存储库
关于android - gradle 的本地模块依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27794168/