Android Studio将本地项目添加到Gradle

时间:2014-04-12 02:51:42

标签: gradle android-studio

screenshot 我附上了当前项目设置的屏幕截图,但是在“库”项目中使用“SampleApp”项目中的代码时遇到了问题。我的项目build.gradle包含以下内容:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

我的settings.gradle包含以下内容:

include ':SampleApp'
include ':library'

我的SampleApp build.gradle包含以下内容:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile project(':library')
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

我的库build.gradle包含以下内容:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 11
    }

    buildTypes {
        release {
            runProguard false
        }
    }
}

奇怪的是,如果我尝试在我的SampleApp项目中包含库项目中的一段代码,我可以添加相关内容,使用AndroidStudio功能添加正确的导入并且没有错误。但是,一旦我去构建,我得到一个错误,说我的包不存在。我也进入了Android Studio项目属性,并添加了库作为SampleApp的依赖项 非常感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

在你的图书馆的 build.gradle 而不是:

apply plugin: 'android'

这样做:

apply plugin: 'android-library'
相关问题