android - gradle 的本地模块依赖关系

标签 android intellij-idea android-gradle-plugin dependency-management build.gradle

我最近决定将我的 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/

相关文章:

java - android应用程序执行过程中的错误

android - 新的 Google Play 控制台版本中发生了数千次奇怪的崩溃

java - 从 Activity 启动 DialogFragment

android - Glide 在构建应用程序时显示错误

android - ListView 上的按钮我想使用 button.setonclicklistener 和 onListItemClick 我需要做什么

android - 第一个 MapActivity 实例是否总是泄漏?

intellij-idea - 使用@import scss 进行 IntelliJ 自动完成时如何处理子目录中的相对图像路径?

java - IntelliJ IDEA + Vagrant : compile and run in VM environment

gradle - 如果我们有 repo 本地导入它,否则通过 maven 下载

android - 如何从 Android aar 文件创建测试 apk?