theblitz
theblitz

Reputation: 6881

Copy task in Gradle not found

I am developing an app in Unity and need to copy some files before the build. I have looked around for how to do this and this is what I created (I removed all the "noise"):

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

allprojects {
   repositories {
      flatDir {
        dirs 'libs'
      }
   }
}

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

android {

    compileSdkVersion  25
      .....
    buildTypes {
     .......
    }

     preBuild.dependsOn copyRes
}

task copyRes(type: Copy) {
    from file("'../../Assets/Plugins/Android/res")
    into file("./src/main/res/values")
}

My build is failing with the following error:

Could not get unknown property 'copyRes' for object of type com.android.build.gradle.AppExtension

Upvotes: 0

Views: 202

Answers (1)

lance-java
lance-java

Reputation: 28071

This is just an ordering issue. You have tried to use copyRes before it exists.

Option 1 - Use a string instead of the variable

preBuild.dependsOn 'copyRes'

Option 2 - Declare the copyRes task first, before the android {...} block

Upvotes: 2

Related Questions