【发布时间】:2021-10-05 17:09:48
【问题描述】:
我正在移动一个在其原始项目中运行的旧项目。但是,它的 gradle 一直在给我一个新项目中的问题。问题是 preBuild 调用无法识别我的 gradle 任务。
我已经尝试将它们转换为使用“copyAppFiles”的引用或直接命名它们而不使用单引号。
Build file 'C:\Users\ZBC\AndroidStudioProjects\MyYapApp\app\build.gradle' line: 88
A problem occurred evaluating project ':app'.
> Could not get unknown property 'copyAppFiles' for project ':app' of type org.gradle.api.Project.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
...
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'copyAppFiles' for project ':app' of type org.gradle.api.Project.
...
at build_9ohkvz8w7llkrdjeut3507o3h.run(C:\Users\ZBC\AndroidStudioProjects\MyYapApp\app\build.gradle:88)
我的 Gradle 文件
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.squareup.sqldelight'
}
android {
defaultConfig {
compileSdkVersion 29
applicationId setPropertyValue('applicationId', 'com.flicast.jw')
targetSdkVersion setPropertyValue('targetSdkVersion', 29)
}
buildTypes {
release {...
}
debug {
debuggable true
resValue "bool", "DEBUG", "true"
}
}
//list flavorDimensions in override priority order
flavorDimensions 'platform', 'theme'
//assign each productFlavor a corresponding flavorDimension
productFlavors {
mobile {
dimension 'platform'
minSdkVersion setPropertyValue('mobileMinSdkVersion', 22)
}
light {
dimension 'theme'
}
dark {
dimension 'theme'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api project(':xyzacore-android')
api project(':app-bridge')
}
task applyAppFiles {
if (!fileTree('../../app-config/src').isEmpty()) {
//copy app-config files to jw-app/src
task copyAppFiles(type: Copy) { //<-------------
from ("../../app-config/src") {
//exclude ""
}
into "src"
}
}
}
def setPropertyValue(parameterName, defaultValue) {
if (rootProject.ext[parameterName]) {
return rootProject.ext[parameterName]
} else {
return defaultValue
}
}
preBuild.dependsOn(copyAppFiles) //<----------------
preBuild.dependsOn(applyAppFiles)
顶级 gradle 设置包括
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.squareup.sqldelight:gradle-plugin:1.2.1"
项目结构设置为
Gradle Plugin Version 3.6.1
Gradle Version 6.3
任何帮助都会很有用。
【问题讨论】:
-
为什么在
task中需要task? -
@Jay 我需要检查我正在复制的文件是否已经可用,然后执行复制。
-
请检查我更新的答案。
标签: android gradle android-gradle-plugin build.gradle gradle-task