I've been reading this tutorial to understand how to create an Android Service for Unity: http://eppz.eu/blog/unity-android-plugin-tutorial-2/
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 build.gradle
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 {
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 ->
// 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;
}
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.
Paste the code on your module's build file, not on the top-level one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With