bigp bigp - 1 year ago 235
Android Question

Could not get unknown property 'android'

I've been reading this tutorial to understand how to create an Android Service for Unity:

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.

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

android.libraryVariants.all { ... }
part was in the tutorial to begin with:

(EDIT: I placed the entire
file here in case there's anything apparent that I'm missing)

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

buildscript {
repositories {
dependencies {
classpath ''

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

allprojects {
repositories {

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

android.libraryVariants.all { variant ->
// Task names.
String pluginName = "DemoPlugin";
String variantName = "${}"; // 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 = "${}-${}.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) {
rename(sourceAARName, targetAARName)
}.group = deployTaskGroup;

Any ideas what could be causing that error?

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.

Answer Source

Paste the code on your module's build file, not on the top-level one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download