如何在Android Studio中使用新的gradle实验

时间:2015-11-29 01:20:36

标签: android-studio gradle gradle-experimental

我用Android Studio NDK创造了一个非常好的世界。根据{{​​3}}的说明,我复制完全相同(只留下一些较新的构建工具版本),但始终出现错误: 错误:(49,1)评估项目':app'时出现问题。

  

无法在项目':app'上找到参数[junit:junit:4.12]的方法testCompile()。

你能告诉我我的HelloWorld有什么问题吗? 这是我的app build.gradle

 apply plugin: "com.android.model.application"

model {
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig.with {
            applicationId = "com.android.services.testjni"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
            buildConfigFields.with {
                create() {
                    type = "int"
                    name = "VALUE"
                    value = "1"
                }

            }
        }
        android.buildTypes {
            release {
                minifyEnabled = false
                proguardFiles.add(file("proguard-rules.pro"))
            }
        }
        android.productFlavors {
            create("flavor1") {
                applicationId = "com.app"
            }
        }
        // Configures source set directory.
        android.sources {
            main {
                java {
                    source {
                        srcDir "src"
                    }
                }
            }
        }
    }
}

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

和build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle-experimental:0.2.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

和gradle-wrapper.properties

#Fri Nov 27 17:00:16 ICT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

1 个答案:

答案 0 :(得分:0)

AFAIK,android插件没有testCompile配置,这是gradle的java插件中的配置,但有一个androidTestCompile。因此,您必须在依赖项中重命名它,如:

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