Android Gradle - 构建库模块会生成意外的.aar

时间:2014-09-10 03:01:17

标签: android android-gradle android-library

我目前正在设置一个多模块项目,具有以下结构:

Project Root
  |- app/
    |- src/
    |- build.gradle
  |- lib
    |- src/
    |- build.gradle
  |- build.gradle
  |- gradle.properties
  |- settings.gradle

当库模块按预期构建时,我得到app模块的以下构建错误:

A problem was found with the configuration of task ':app:prepareProjectRootLib10Library'.
> File 'C:\projects\Project Root\lib\build\outputs\aar\lib-1.0.aar' specified for property 'bundle' does not exist.

就我的构建脚本而言,我认为我的构建脚本没有任何问题。同时,当我为我的库项目查找生成.aar时,我改为查找lib-1.0-SNAPSHOT.aar文件,这解释了问题。虽然手动重命名该文件以匹配构建脚本所期望的问题,但我需要一个需要手动工作的解决方案。有没有办法修改构建脚本,以便应用程序模块可以获取它需要的库项目文件?

如果有帮助,下面是app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 20
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/resources']
            res.srcDirs = ['src/res']
            assets.srcDirs = ['src/assets']
        }
        androidTest {
            java.srcDirs = ['src/androidTest/java']
            resources.srcDirs = ['src/androidTest/resources']
            res.srcDirs = ['src/res']
            assets.srcDirs = ['src/assets']
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile project(':lib')
    compile 'com.android.support:support-v4:20.0.0'
}

这是lib/build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 20
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java']
            resources.srcDirs = ['src/main/resources']
            res.srcDirs = ['src/res']
            assets.srcDirs = ['src/assets']
        }
        androidTest {
            java.srcDirs = ['src/androidTest/java']
            resources.srcDirs = ['src/androidTest/resources']
            res.srcDirs = ['src/res']
            assets.srcDirs = ['src/assets']
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile 'com.android.support:support-v4:20.0.0'
}

0 个答案:

没有答案