我一直在阅读本教程,了解如何为Unity创建Android服务: http://eppz.eu/blog/unity-android-plugin-tutorial-2/
这里有一个Gradle构建脚本片段,所以我复制了它并略微修改它,以便它可以正确地部署到我的Unity项目。
但是当我运行/同步Gradle脚本时,它似乎在抱怨' android'变量/关键字(或其他任何东西)。我不认为这是由于我的修改引起的,因为android.libraryVariants.all { ... }
部分是在教程中开始的:
(编辑:我将整个build.gradle
文件放在此处,以防有任何明显遗漏的内容
// 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;
}
任何想法可能导致该错误?
错误:(25,1)评估根项目' DemoService'时出现问题。 无法获得未知的财产' android'对于根项目' DemoService'类型为org.gradle.api.Project。
答案 0 :(得分:4)
将代码粘贴到模块的构建文件中,而不是顶层文件。