Could not get unknown property 'android'
<p>I've been reading this tutorial to understand how to create an Android Service for Unity:
<a href="http://eppz.eu/blog/unity-android-plugin-tutorial-2/" rel="nofollow noreferrer">http://eppz.eu/blog/unity-android-plugin-tutorial-2/</a></p>

<p>And there's a Gradle build script snippet shown there, so I copied it and slightly modified it so it can deploy to my Unity project properly.</p>

<p>But when I run / Sync the Gradle script, it seems to complain about the 'android' variable / keyword (or whatever this is) in it. I don't think this is caused by my modifications since the <code>android.libraryVariants.all { ... }</code> part was in the tutorial to begin with:</p>

<p>(<strong>EDIT</strong>: I placed the entire <code>build.gradle</code> file here in case there's anything apparent that I'm missing)</p>

<pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

android.libraryVariants.all { variant -&gt;
    // Task names.
    String pluginName = "DemoPlugin";
    String variantName = "${variant.name.capitalize()}"; // Like 'Debug'
    String deployTaskGroup = "plugin";
    String deployTaskName = "deploy${variantName}PluginArchive"; // Like 'deployDebugPluginArchive'
    String dependencyTaskName = "assemble${variantName}"; // Like 'assembleDebug'
    // Source.
    String sourceAARFolder = "${buildDir.getPath()}/release-jars/";
    String sourceAARName = "${project.name}-${variant.name}.jar";

    // Pierre: Unity project directory
    String targetProjDir = System.env.UNITY_PROJECT;

    // Target.
    String targetAssetFolder = "Assets/Plugins/${pluginName}";
    String targetAARFolder = "${targetProjDir}/${targetAssetFolder}"; // Navigate into 'Assets'
    String targetAARName = "${pluginName}.jar"; // The form you ship your plugin
    // Create task.
    task(deployTaskName, dependsOn: dependencyTaskName, type: Copy) {
        from(sourceAARFolder)
        into(targetAARFolder)
        include(sourceAARName)
        rename(sourceAARName, targetAARName)
    }.group = deployTaskGroup;
}
</code></pre>

<p>Any ideas what could be causing that error?</p>

<blockquote>
  <p>Error:(25, 1) A problem occurred evaluating root project 'DemoService'.
  Could not get unknown property 'android' for root project 'DemoService' of type org.gradle.api.Project.</p>
</blockquote>