【问题标题】:How to use new gradle experimental in Android Studio如何在 Android Studio 中使用新的 gradle 实验
【发布时间】:2015-11-29 01:20:35
【问题描述】:

我用 Android Studio NDK 创造了一个非常好的世界。按照http://tools.android.com/tech-docs/new-build-system/gradle-experimental 的指示,我复制了完全相同的内容(只留下了一些较新的构建工具版本),但总是出现错误: 错误:(49, 1) 评估项目 ':app' 时出现问题。

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

你能告诉我我的 HelloWorld 有什么问题吗? 这是我的应用 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

【问题讨论】:

    标签: android-studio gradle gradle-experimental


    【解决方案1】:

    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'
    }
    

    【讨论】:

    • 同样的错误,斯坦尼斯拉夫。然后它说找不到androidTestCompile。我用 gradle 2.5 添加了 android 插件版本 1.3.1 然后它说找不到 com.android.model.application。你对此有什么想法吗?谢谢和最好的问候,
    • @CuongPhan android 插件与实验不同,我想。要使用实验性,您必须应用上面有问题的确切插件。您能否尝试不包含测试依赖项来检查,现在没有 jUnit 是否可以。?
    • @CuongPhan 我查看了 github 上的示例,但没有发现 fpr app 项目的测试依赖项。不太确定,怎么做。或者,您可以尝试应用 java 插件,然后您将能够提供 testCompile 配置,但不确定这是处理此问题的正确方法。
    猜你喜欢
    • 2016-12-24
    • 2013-07-17
    • 2016-07-02
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多