尝试包含本地库时,Android Studio Gradle构建失败

时间:2014-03-21 01:28:13

标签: android android-studio android-gradle

我得到的错误是: Gradle'MyProject'项目刷新失败: 在项目':myproject'中找不到带有路径'libraries:mylibrary_sdk'的项目

这是我的设置gradle

include ':libraries:mylibrary_sdk',':myproject'

顶级构建gradle

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

myproject build gradle

apply plugin: 'android'

dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile project ("libraries:mylibrary_sdk")
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
}

mylibrary_sdk build gradle

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
     }
     buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

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

我已经阅读了所有相似的答案,但我仍然坚持这个问题。如果我删除编译项目(“libraries:mylibrary_sdk”)和库:mylibrary_sdk include,那么myproject构建正常,只是无法访问mylibrary。 libraries文件夹与settings.gradle,顶级build.gradle和myproject文件夹处于同一级别。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

这是有效的,添加回答..以后可能会帮助某人

dependencies { compile 'com.android.support:support-v4:19.0.1' compile project (":libraries:mylibrary_sdk") }