简体   繁体   English

带有 gradle 的本地模块依赖项

[英]Local module dependencies with gradle

I have recently decided to switch my android project to the gradle build system from ant.我最近决定将我的 android 项目从 ant 切换到 gradle 构建系统。 Manually managing library and module dependencies between members of our team was quickly becoming too much work.手动管理我们团队成员之间的库和模块依赖关系很快变得太多工作。

Everything began smooth.一切开始顺利。 I have created a new gradle project, moved my sources and resources, and have gotten rid of all of the major third-party library .jars that we're hanging around my /libs folder so I could utilize the new gradle maven central dependencies.我创建了一个新的 gradle 项目,移动了我的源代码和资源,并摆脱了我们挂在/libs文件夹中的所有主要第三方库 .jar,这样我就可以利用新的 gradle maven 中央依赖项。 No problems there.那里没有问题。

Now I am trying to find a good way to set up dependencies on some less popular modules that are not on maven central.现在我试图找到一种好方法来设置对一些不在 maven central 上的不太流行的模块的依赖关系。 I use a few small android modules (eg a form validator, helper util module, etc) which I have become dependent on.我使用了一些我已经变得依赖的小型 android 模块(例如表单验证器、助手 util 模块等)。 The problem is that these modules are not simply .jars, but have resources as well.问题是这些模块不仅仅是 .jars,而且还有资源。 As far as I can tell, I can't just put these modules in my /libs folder and have gradle set up dependencies to them.据我所知,我不能只是将这些模块放在我的/libs文件夹中,并让 gradle 为它们设置依赖项。 I have read up on .aar files a bit and am looking for some advice on whether they are the answers to my problems or I am overlooking something simple.我已经阅读了一些 .aar 文件,正在寻找一些建议,看看它们是否是我问题的答案,或者我忽略了一些简单的东西。 Below is my current directory structure (with some comments) and my gradle.build .下面是我当前的目录结构(有一些注释)和我的gradle.build

directory structure目录结构

/<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构建.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'
} 

You can add your local maven repository to your build.gradle:您可以将本地 Maven 存储库添加到 build.gradle:

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
    flatDir {
        dirs 'libs'
    }
}

The location of the local repository depends on the OS.本地存储库的位置取决于操作系统。 In Linux it's $HOME/.m2/repository在 Linux 中它是 $HOME/.m2/repository

您目前可以使用 JitPack。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM