Gradle无法解析符号,但它确实存在

3

I've the following build.gradle file:

import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask

apply plugin: 'kotlin-multiplatform'
apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 19
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
    testImplementation 'com.google.truth:truth:0.42'

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
    androidTestImplementation 'com.google.truth:truth:0.42'
}

kotlin {
    targets {
        jvm("jvm")
        android("android")
        iosArm32("ios32")
        iosArm64("ios64")
        iosX64("emulator")

        configure([ios32, ios64, emulator]) {
            binaries.framework('HyModule')
        }
    }

    sourceSets {
        commonMain.dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib-common'
        }
        jvmMain.dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
        }
        androidMain.dependencies {
            implementation 'org.jetbrains.kotlin:kotlin-stdlib'
        }
        androidMain.dependsOn jvmMain
    }

    task fatFramework(type: FatFrameworkTask) {
        // the fat framework must have the same base name as the initial frameworks
        baseName = "HyModule"

        final File frameworkDir = new File(buildDir, "xcode-frameworks")
        destinationDir = frameworkDir

        // specify the frameworks to be merged
        from(
                targets.ios32.binaries.getFramework('HyModule', 'RELEASE'),
                targets.ios64.binaries.getFramework('HyModule', 'RELEASE'),
                targets.emulator.binaries.getFramework('HyModule', 'RELEASE')
        )

        doLast {
            new File(frameworkDir, 'gradlew').with {
                text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
                setExecutable(true)
            }
        }
    }
}

// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
    compileClasspath
}

tasks.build.dependsOn fatFramework

import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask被标记为红色错误

无法解析符号“FatFrameworkTask”

尽管一切正常,但我不喜欢在我的项目中出现错误。

(说明:该段文字是对一个编程问题的描述,其中的“FatFrameworkTask”是一个类名,因为没有上下文信息,所以无法确定如何翻译最准确。)

1
考虑使用Gradle Kotlin DSL而不是Groovy脚本-它具有更好的IDE支持,包括类型和调用检查以及代码补全。 - hotkey
你解决了这个问题吗?我使用build.gradle.kts和gradle编译时也遇到了同样的问题。 - Pavel
@Pavel 很遗憾,没有。 - Benjamin
似乎在1.3.21版本中缺少了这个导入。但是在1.3.30版本中有。 - Pavel
3个回答

1
尝试。
import org.jetbrains.kotlin.gradle.tasks.*

我遇到了相同的问题,不知道为什么这样做有效。

0
如果Gradle任务正常工作,可能是IntelliJ中的一个视觉错误,这在我身上经常发生。
尝试重新启动IntelliJ或Android Studio。

0
在我的情况下,不要使用import,而是使用类的完整路径,例如,以下代码:org.jetbrains.kotlin.gradle.tasks.KotlinCompile
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '17'
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接