编译时未解决的参考,但Intellisense提供

时间:2019-07-10 16:38:31

标签: android kotlin flutter

我正在为Flutter开发音频处理库,但遇到了我的原生Kotlin类之一的问题。在下面的代码示例中,编译器抱怨copyInto数组上对samples的调用是未解决的引用。据我所知,我已经确保它是IntArray,并且在我输入“ samples”时,Android Studio中的Intellisense甚至会弹出copyInto作为选项。

这是我的班级代码:

package com.----.audio_channels

import kotlin.math.abs
import kotlin.math.min

abstract class AudioTrackBuffer constructor(val loop: Boolean) {
    var position: Int = 0

    abstract fun getSamples(sampleCount: Int): IntArray
    abstract fun isComplete(): Boolean
    abstract fun dispose()
}

class RawAudioBuffer constructor(private val samples: IntArray, loop: Boolean, delay: Int): AudioTrackBuffer(loop) {

    init {
        position = -delay
    }

    override fun getSamples(sampleCount: Int): IntArray {
        val slice: IntArray

        if (position < 0) {
            slice = IntArray(sampleCount) { 0 }

            if (position + sampleCount < 0) {
                position += sampleCount
                return slice
            }

            val offset = abs(position)
            samples.copyInto(slice, offset, 0, min(sampleCount - offset, samples.size)) // Error
        } else {
            slice = samples.copyOfRange(position, min(position + sampleCount, samples.size))
            position += slice.size
        }

        return slice
    }

    override fun isComplete(): Boolean {
        return position >= samples.size
    }

    override fun dispose() {}
}

这是编译错误:

Launching lib\main.dart on SM N960U in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
e: E:\flutter\workspace\audio_channels\android\src\main\kotlin\com\----\audio_channels\AudioTrackBuffer.kt: (33, 21): Unresolved reference: copyInto

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':audio_channels:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Finished with error: Gradle task assembleDebug failed with exit code 1

1 个答案:

答案 0 :(得分:3)

copyInto以来,1.3函数可用。当前,您正在使用1.2.71,然后会收到错误消息Unresolved reference: copyInto
因此,将您的应用kotlin版本更新为> = 1.3将解决您的问题