Gradle嵌套,多项目,共享库环境设置

时间:2014-07-23 12:29:16

标签: android gradle dependencies android-studio

过去几天我一直在尝试从Eclipse迁移到Android Studio,并且遇到了一些有关依赖项设置的问题......

这里基本上是现在存在的eclipse项目依赖结构

- External Library 1
- External Library 2
- External Library 3
.
.
.
- External Library n
    |
    - CustomSetOfLibrariesProject (Library project with lots of custom classes, custom views, backend helper classes...)
        |
        |
        - App_Type_A_Project - (Library project, on top of which I can create different apps (App001, App002) with different names, graphics, package etc.
        |   |
        |   - App_Type_A_Package001, App_Type_A_Package002, etc. ... (Actual final Android Type_A product submitted to Google Play)
        |
        |
        - App_Type_B_Project - (Library project, on top of which I can create different apps (App001, App002) with different names, graphics, package etc.
            |
            - App_Type_B_Package001, App_Type_B_Package002, etc. ... (Actual final Android Type_B product submitted to Google Play)

整个项目结构包括:

' CustomSetOfLibrariesProject' - 许多自定义类,自定义视图,后端帮助程序类...此项目依赖于所有必需的外部库,如磁带,android async http

每个项目总是基于' CustomSetOfLibrariesProject' - 所以这是一个很大的共享库,已经依赖于一些外部库

这是磁盘文件结构

TOP DIRECTORY
    |
    - libs-android
    |   |
    |   - custom_set_of_libraries_project
    |   - external_lib_1
    |   - external_lib_2
    |
    - app_type_A_project
    - app_type_B_project
    - android-release
        |
        - app_type_A_package001
        - app_type_A_package002
        - app_type_B_package001
        - app_type_B_package002

我发现在Android Studio中很难实现这种依赖关系结构,显然我遇到了错误:配置名称'默认'没找到。'。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我所做的是每个外部库,我创建一个项目并单独维护它(通常是从github中提取的项目和我自定义/错误修复)

构建外部库的项目以生成.jar或.aar文件。您可以将此文件复制到项目的libs文件夹或链接它(例如ln -s ../../ExternalLib/build/lib.jar ./lib.jar)

创建一个产品项目,并为每个App创建一个Module。将所有外部lib的jar文件链接或复制到libs'夹

如果您正在使用任何外部库

,请编辑每个模块的build.gradle文件
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // or
    compile(name: 'externalLib1', ext: 'jar')
    compile(name: 'externalLib2', ext: 'aar')
}

http://oi61.tinypic.com/n4fgp4.jpg

3级深层次结构:

项目'  gradle:settings.gradle

include ':app', ':lib1', ':CustomSetOfLibrariesProject'

外部库1:lib1.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

共享库的gradle:CustomSetOfLibrariesProject.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':lib1')
}

产品应用程序的gradle:app.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':CustomSetOfLibrariesProject')
}