I use some SKIA API like `Image.makeFromEncoded()`...
# compose-ios
s
I use some SKIA API like
Image.makeFromEncoded()
in my compose code gets a unresolved reference as soon as I add the
iosArm64()
target. If I try to add
api("org.jetbrains.skiko:skiko:0.7.58")
to
commonMain
this results in errors like this:
Copy code
ld: warning: object file (/var/folders/jw/hb2y762x2jg3y14lzck8_fqc0000gn/T/included15295158996419610357/libparticles.a(libparticles.SkParticleBinding.o)) was built for newer iOS version (11.0) than being linked (9.0)
ld: warning: object file (/var/folders/jw/hb2y762x2jg3y14lzck8_fqc0000gn/T/included15295158996419610357/libskresources.a(libskresources.SkResources.o)) was built for newer iOS version (11.0) than being linked (9.0)
ld: warning: object file (/var/folders/jw/hb2y762x2jg3y14lzck8_fqc0000gn/T/included15295158996419610357/libparticles.a(libparticles.SkParticleDrawable.o)) was built for newer iOS version (11.0) than being linked (9.0)
Is this the wrong way to add skiko? I was thinking SKIA should be already used for Compose for iOS. I'm on Apple Silicon.
1
o
These are warnings. The error message is probably at the bottom. Could you please check the error message?
compose code gets a unresolved reference as soon as I add the
iosArm64()
target
Does it fail to compile? Or it’s only in IDE?
s
The error messages start with:
Copy code
Undefined symbols for architecture arm64:
  "_CGAffineTransformConcat", referenced from:
      SkScalerContext_Mac::generatePath(SkGlyph const&, SkPath*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
and the last line is
Copy code
ld: symbol(s) not found for architecture arm64
My configuration looks like this:
Copy code
val xcf = XCFramework()

listOf(
    /* App Store */
    iosArm64(),
    /* Apple Silicon iOS Simulator */
    iosSimulatorArm64(),
    /* macOS Devices */
    macosX64(),
    macosArm64()
).forEach {

    it.binaries.framework(
        buildTypes = setOf(NativeBuildType.RELEASE)
    ) {
        baseName = "compose"
        /* Part of the XCFramework */
        xcf.add(this)
        /* Bitcode was deprecated with XCode 14 */
        embedBitcode("disable")
    }
}
Same error if build from command line without IDEA.
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compose:linkReleaseFrameworkIosArm64'.
> Compilation finished with errors
Copy code
Kotlin/Native on iOS(arm64 and x64)
Kotlin/Native on macOS (arm64 and x64)
Both are listed as supported platforms on the skiko project page. So I assumed it should work. I'm not sure if the way I specified the dependency is correct.
o
Copy code
SkScalerContext_Mac
it’s rather an unexpected symbol for ios. Did it fail for iosSimulatorArm64 ? I’m not sure if Image.makeFromEncoded() is the cause. We use it in demos which worked fine. Do you have a reproducer that could be shared?
s
Yes, it also fails if I just use iosSimulatorArm64 as a target. I will try to build a reproducer.
m
Just in order to help clarifying this issue. This is a code fragment that I use on my Mac for macOS and iOS without having to add any extra dependencies.
Copy code
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asComposeImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import de.mpmediasoft.system.ImageFactoryService
import org.jetbrains.skia.Bitmap
import org.jetbrains.skia.ColorAlphaType
import org.jetbrains.skia.Image
import org.jetbrains.skia.ImageInfo

actual class ImageFactoryServiceImpl actual constructor() : ImageFactoryService {

    // Desktop and UIKit implementation (actually works on all Skia targets)

    override fun imageBitmapFromBytes(encodedImageData: ByteArray): ImageBitmap {
        return Image.makeFromEncoded(encodedImageData).toComposeImageBitmap()
    }
As you can see I directly use the SKIA binding. This works nicely on the simulator (I don’t have a real device) and I am on an Intel Mac but I would assume that this should work on an M1/M2 Mac too.
d
You can't use Image.makeFromEncoded() inside commonMain sourceSet
1
You can use it in iosMain sourceSet
There is a related bug in the Kotlin IDE plugin https://youtrack.jetbrains.com/issue/KT-58107
s
That may indeed be related to my problem. I stripped my app down to a minimalistic app for the reproducer and unfortunately that works. So right now I'm investigating what exactly makes it fail for me.
m
Exactly, that is the reason why I use it in this “actual” class.
d
@Stefan Oltmann Anyway, minimalistic reproducer will be helpfull
You can also look at isStatic = true in gradle.kts
s
I try to make it fail. Or I will figure out what I did wrong.
I have seen
isStatic = true
only recently in the examples, but I don't know yet what it does.
d
it means use kotlin libraries as a static Xcode framework
It should be set to true right now
s
Is that the default if I do not specify it?
d
Later we will support dynamyc frameworks as well (isStatic = false by default)
By default it is false, so you should set it to true in gradle.kts
s
That setting indeed makes a difference. My reproducer fails without setting
isStatic = true
. I missed this configuration as I just copied the old block from my
shared
module over to my
compose
module. 🙈 Thank you for pointing that out.
@Michael Paus Thank you. You are right, I don't need extra dependencies.
983 Views