Android Studio上新的实验性Gradle for NDK中的preBuild依赖项

时间:2015-10-17 20:25:16

标签: android gradle android-ndk

最近我决定在Android Studio中使用新的NDK插件

所需的更改已解释为here

我的build.gradle已成功移植。今天我决定我需要一个复制任务才能将文件复制到我的“资产”文件夹中。

在线搜索说我必须使用'preBuild.dependsOn taskName'行,我确信它对普通Gradle有效,但在新实验中失败(引入'模型'行为)

现在我的build.gradle失败了。

Error:(25, 0) Could not find property 'preBuild' on root project 'Android'.

我确信该任务已正确定义,因为错误来自preBuild ... line

这是我的build.gradle:

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

allprojects {
    repositories {
        jcenter()
    }
}

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

task copyWebViewAssets(type: Copy){
    from '../Common/WebView'
    into 'src/main/assets'
    include('**/*')
}

preBuild.dependsOn copyWebViewAssets

model {
    compileOptions.with {
        sourceCompatibility=JavaVersion.VERSION_1_7
        targetCompatibility=JavaVersion.VERSION_1_7
    }
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"

        defaultConfig.with {
            applicationId = "com.company.product"
            minSdkVersion.apiLevel = 9
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.ndk {
        moduleName = "native"
    }
    android.buildTypes {
        release {
            minifyEnabled = false
        }
        debug {
            ndk.with {
                debuggable = true
            }
        }
    }
    android.productFlavors {
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
}

我想再次提到这与NDK的新实验Gradle有关。我目前使用的是Gradle 2.5上的Android Studio 1.4。

感谢您的支持

1 个答案:

答案 0 :(得分:1)

使用compileTask而不是prebuild

它对我有用。

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(changeNamespace)
}