简体   繁体   English

Kotlin 找不到符号 Function1 构建错误

[英]Kotlin cannot find symbol Function1 build error

Below is the following test method I have built to make my life slightly easier using Glide.下面是我构建的以下测试方法,使我使用 Glide 的生活更轻松。

    suspend fun retrieveImage(
        glideRequests: GlideRequests,
        uri: String,
        options: (GlideRequest<Drawable>.() -> Unit)? = null,
        targetCallback: ((FutureTarget<Drawable>) -> Unit)? = null
    ): Drawable? {
        // The GlideRequest we should use to run our request
        val request = glideRequests.load(uri)

        // Apply the options to be used for our request
        options?.invoke(request)

        // Callback for our Future object so that it can be cancelled if necessary
        val drawableFuture = request.submit()
        targetCallback?.invoke(drawableFuture)

        return try {
            withContext(Dispatchers.IO) {
                try {
                    drawableFuture.get()
                } catch (unknownHostException: UnknownHostException) {
                    // Return null, this method was run with no network
                    null
                } catch (interruptionException: InterruptedException) {
                    // Request has been cancelled
                    null
                }
            }
        } catch (cancellationException: CancellationException) {
            // Coroutine has been cancelled
            null
        }
    }

It builds out to be the following for the JVM它构建为 JVM 的以下内容

import android.graphics.drawable.Drawable;
import com.bumptech.glide.request.FutureTarget;
import io.vadgroup.cirqle.application.GlideRequest;
import io.vadgroup.cirqle.application.GlideRequests;
import kotlinx.coroutines.Dispatchers;
import java.net.UnknownHostException;

@kotlin.Metadata(mv = {1, 1, 16}, bv = {1, 0, 3}, k = 1, d1 = {"\u00000\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u00c6\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002\u00a2\u0006\u0002\u0010\u0002J^\u0010\u0003\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\u001b\b\u0002\u0010\t\u001a\u0015\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\u000b\u0018\u00010\n\u00a2\u0006\u0002\b\f2\u001c\b\u0002\u0010\r\u001a\u0016\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\u000e\u0012\u0004\u0012\u00020\u000b\u0018\u00010\nH\u0086@\u00f8\u0001\u0000\u00a2\u0006\u0002\u0010\u000f\u0082\u0002\u0004\n\u0002\b\u0019\u00a8\u0006\u0010"}, d2 = {"Lio/vadgroup/cirqle/utilities/GlideUtil;", "", "()V", "retrieveImage", "Landroid/graphics/drawable/Drawable;", "glideRequests", "error/NonExistentClass", "uri", "", "options", "Lkotlin/Function1;", "", "Lkotlin/ExtensionFunctionType;", "targetCallback", "Lcom/bumptech/glide/request/FutureTarget;", "(Lerror/NonExistentClass;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "app_debug"})
public final class GlideUtil {
    public static final io.vadgroup.cirqle.utilities.GlideUtil INSTANCE = null;

    @org.jetbrains.annotations.Nullable()
    public final java.lang.Object retrieveImage(@org.jetbrains.annotations.NotNull()
    GlideRequests glideRequests, @org.jetbrains.annotations.NotNull()
    java.lang.String uri, @org.jetbrains.annotations.Nullable()
    Function1<GlideRequest<android.graphics.drawable.Drawable>, kotlin.Unit> options, @org.jetbrains.annotations.Nullable()
    kotlin.jvm.functions.Function1<? super com.bumptech.glide.request.FutureTarget<android.graphics.drawable.Drawable>, kotlin.Unit> targetCallback, @org.jetbrains.annotations.NotNull()
    kotlin.coroutines.Continuation<? super android.graphics.drawable.Drawable> p4) {
        return null;
    }

    private GlideUtil() {
        super();
    }
}

If you look at the above Java code, one can see two different Function1 objects, one with the complete Kotlin path and one without it.如果您查看上面的 Java 代码,您可以看到两个不同的 Function1 对象,一个具有完整的 Kotlin 路径,一个没有它。

I am suspecting this is happening due to a clash with Arrow-Core library I have since they also have a Function1 object.我怀疑这是由于与我拥有的 Arrow-Core 库发生冲突而发生的,因为它们也有一个 Function1 对象。 I completely removed the library, cleaned the cache and build, however, I still run across this problem.我完全删除了库,清理了缓存并构建,但是,我仍然遇到了这个问题。

I currently have used both Kotlin versions 1.3.70 and 1.3.71我目前使用了 Kotlin 版本 1.3.70 和 1.3.71

I added the following item to the top of the import list我将以下项目添加到导入列表的顶部

import kotlin.jvm.functions.*

Although greyed out and seeming to be unused, I was able to correctly build the project.尽管变灰且似乎未使用,但我能够正确构建项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM