【问题标题】:Kotlin cannot find symbol Function1 build errorKotlin 找不到符号 Function1 构建错误
【发布时间】:2020-04-02 02:09:26
【问题描述】:

以下是我构建的以下测试方法,使用 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
        }
    }

它在 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();
    }
}

如果查看上面的 Java 代码,可以看到两个不同的 Function1 对象,一个带有完整的 Kotlin 路径,一个没有。

我怀疑这是由于与我拥有的 Arrow-Core 库发生冲突而发生的,因为它们也有一个 Function1 对象。我完全删除了库,清理了缓存并构建,但是我仍然遇到这个问题。

我目前使用了 Kotlin 版本 1.3.70 和 1.3.71

【问题讨论】:

    标签: java android kotlin compilation


    【解决方案1】:

    我将以下项目添加到导入列表的顶部

    import kotlin.jvm.functions.*

    虽然显示为灰色且似乎未使用,但我能够正确构建项目。

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 2019-05-07
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多