Gradle在解析符号时无法解析符号

kknvjkwl  于 2023-02-23  发布在  其他
关注(0)|答案(3)|浏览(307)

我有以下build.gradle文件:

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”
即使一切都很好,我不喜欢有错误在我的项目.

aemubtdh

aemubtdh1#

试试看

import org.jetbrains.kotlin.gradle.tasks.*

我也遇到了同样的问题,不知道为什么会这样

oyxsuwqo

oyxsuwqo2#

如果Gradle任务运行正常,则可能是IntelliJ中的视觉错误,我通常会遇到这种情况。
尝试重新启动IntelliJ或Android Studio

g6ll5ycj

g6ll5ycj3#

在我的例子中,不要使用import,而是使用类的完整路径,例如,遵循org.jetbrains.kotlin.gradle.tasks.KotlinCompile

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '17'
    }
}

相关问题