Android Gradle依赖与多级依赖

时间:2018-06-20 19:56:50

标签: android gradle build.gradle gradle-plugin

我有一个Android应用程序,该应用程序依赖于称为B的依赖关系,而B依赖于称为C的依赖关系,C包含一些aar库和B需要的一些资源。以下是我正在使用的配置。 Gradle要求我在C中找到的库的'app'和依赖项B中设置存储库-> flatDir-> dirs,这似乎不正确。

为应用配置

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        targetSdkVersion rootProject.ext.targetSdkVersion
    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
}

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

    compile dep.firebaseMessaging
    compile 'com.android.support:multidex:1.0.1'
}

apply from: '../B/config.gradle'

repositories {
    flatDir {
        dirs '../C/libs'
    }
}

为B配置

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        consumerProguardFile 'proguard-rules.pro'
    }
}

dependencies {
    compile(project("C"))
}

repositories {
    flatDir {
        dirs '../C/libs'
    }
}

为C配置

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        consumerProguardFile 'proguard-rules.pro'
    }
}

repositories {
    flatDir {
        dirs "libs"
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile(name: 'library1', ext: 'aar')
    compile(name: 'library2', ext: 'aar')
}

library1和library2位于依赖项C的libs目录中,如果我不包含应用程序和依赖项B中的存储库-> flatDir-> dirs,我会得到

Could not resolve all dependencies for configuration ':B'.
     > Could not find :library1:.
       Required by:
           project :B > project :C

如果我确实包含lib目录,那么我会得到一个例外-

Caused by: com.android.ide.common.process.ProcessException: Error while executing process /Android/sdk/build-tools/27.0.3/aapt with arguments

0 个答案:

没有答案