Reputation: 24671
I'm working on an audio processing library for Flutter, and I'm running into an issue with one of my native Kotlin classes. In the code sample below, the compiler is complaining that the call to copyInto
on the samples
array is an unresolved reference. As far as I can tell, I've made sure that it is an IntArray
, and Intellisense in Android Studio even brings up copyInto
as an option when I type "samples.".
Here is my class code:
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() {}
}
And here is the compile error:
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
Upvotes: 1
Views: 1654
Reputation: 60923
The copyInto
function available since kotlin 1.3
. Currently, you are using 1.2.71
then you get error Unresolved reference: copyInto
.
Therefore, update your app kotlin version to >= 1.3 will solve your problem
Upvotes: 4