I'm creating an android live wallpaper using Kotlin. This requires a class that extends WallpaperService, which contains an inner class that extends WallpaperService.Engine.
So I've written this:
import android.service.wallpaper.WallpaperService
import android.service.wallpaper.WallpaperService.Engine
public class MyWallpaperService : WallpaperService() {
override fun onCreateEngine(): Engine = MyEngine()
private inner class MyEngine : Engine() {
}
}
The problem is that I'm getting the following 2 errors at compile time:
Error:java.lang.RuntimeException: Error generating constructors of class MyEngine with kind IMPLEMENTATION
Error:java.lang.UnsupportedOperationException: Don't know how to generate outer expression for lazy class MyWallpaperService
I cant figure out why this is happening so any help would be greatly appreciated.
The best solution I have found is to use an intermediate Java class:
public class Intermediate extends WallpaperService.Engine {
public Intermediate(WatchfaceService outer) {
outer.super();
}
}
Then the inner class in your Kotlin WallpaperService should inherit Intermediate, passing the outer class as parameter.
public class MyWallpaperService : WallpaperService() {
override fun onCreateEngine(): Engine = MyEngine()
private inner class MyEngine : Intermediate(this) {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With