-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin Multiplatform (iOS): not working with Cocoapods plugin #1442
Comments
Hi, i have the same problem when build with gradlew assemble, any suggestion? |
Stack trace? |
|
In the gradle i have:
|
@alfdev where exactly do you have it? do you have some example? |
I have the same problem when I use the Cocoapods plugin. The workaround from kpgalligan (setting the linker options in Xcode) is working but setting the linker options in gradle seems to have no effect. Am I doing something wrong here?
Also I found this issue JetBrains/kotlin-native#3672 . Does anyone know if “extraOpts” or “compilerArgs” work with the Cocoapods plugin in general ? |
The linker option in Xcode isn't a workaround. That's when Xcode is linking
your kotlin code with the rest of the iOS code, and it needs to explicitly
link to sqlite3. You'll *also* need to do that in gradle if running tests,
because that's building an executable without an explicit Xcode project.
…On Sun, Mar 29, 2020 at 8:18 AM Fabian ***@***.***> wrote:
I have the same problem when I use the Cocoapods plugin. The workaround
from kpgalligan (setting the linker options in Xcode) is working but
setting the linker options in gradle seems to have no effect.
Am I doing something wrong here?
val isDevice = System.getenv("SDK_NAME")?.startsWith("iphoneos") == true
if (isDevice)
iosArm64("ios")
else
iosX64("ios")
targets.getByName<KotlinNativeTarget>("ios").compilations.forEach {
it.kotlinOptions.freeCompilerArgs += arrayOf("-linker-options", "-lsqlite3")
}
Also I found this issue JetBrains/kotlin-native#3672
<JetBrains/kotlin-native#3672> . Does anyone
know if “extraOpts” or “compilerArgs” work with the Cocoapods plugin in
general ?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1442 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQWICSXJANRGBECOSTZRTRJ44CTANCNFSM4IOB6XDA>
.
--
Kevin Galligan
https://twitter.com/kpgalligan
|
@HFabi I ran into the same issue although I'm not using the Cocoapods plugin but the packForXCode gradle taks as in the Kotlin MPP for Android-iOS example and then linking the produced framework directly in Xcode. I was able to fix the issue by adding the linker options as follows:
Maybe adding the linker options to the binaries may help in your case, too.
|
Hello, I try to add This is my build.gradle :
|
@Yeeeeeeah before I switched to the cocoapods plugin, I also used the packForXCode approach from the tutorial. There I could set linkSqlite = true, perhaps that solves your problem.
|
Adding
Referenced: |
See: https://github.com/touchlab/KaMPKit/blob/4c56f296af74c25dc425d7bf488e7ae83aae6593/docs/IOS_PROJ_INTEGRATION.md - empty project created from Xcode - follow instructions from previous link - also added compile flag sqldelight/sqldelight#1442 (comment)
Thank you very much. It helped me very much. |
Not working :(
The only working solution is -lsqlite3 flag in Other Liker Flags of Xcode which is suggested by @kpgalligan |
This is kind of old, but the above message isn't really correct. This error:
is totally unrelated. This happens occasionally when running a fresh build of a Kotlin framework built with the cocoapods plugin. You essentially need to run Here's the summary as best I can explain it. The sqldelight driver needs to have an instance of the sqlite library to link against for everything to work. A version ships with iOS, and you can use that by adding I will add to the statement above that we almost always use static frameworks. There are reasons why they tend to be the better option, so I wouldn't pick dynamic frameworks just because you can avoid I think the confusion here is more around how iOS (or most native builds) link to things. It's just kind of different than what we might be used to in the JVM. There are benefits. If you want to use SQLCIpher in your production build, but regular sqlite in your test build(s), that's pretty easy to support. You just link to one or the other when it's time to output a binary. That's kind of beyond the scope for today, but doable (you can also ship your own builds of sqlite from source. Android, on the other hand, makes this more complicated as you also need to maintain and ship an implementation of the driver, but I digress). TL;DR linking to the sqlite3 library isn't a workaround. It's just one of the things you need to do. In some contexts, it happens automatically, and in others explicitly, but if you're hitting sqlite on iOS, the linking happened somewhere. |
hello can anyone make a just an registration page and Connect with database and when data inserted it shows in List-View |
@Rohit-pawar902 Are you asking for a sample app using Kotlin native? There are many. Ours: https://github.com/touchlab/KaMPKit |
I've got |
@ArtRoman thank you after 2 days of struggle it works for me 👌🏻👌🏻 |
@ArtRoman
any insights what might be the problem? getting this error
|
Try to use the full format:
|
Swift UI previews, AFAIK, require dynamic frameworks. That has nothing to do with the sqlite linking errors. SPM support in KMP doesn't carry along the linking params. I believe making the framework dynamic ( Again, when you see:
It's a linking issue, and it means you need I ran into this exact problem, live, less than a week ago: https://youtu.be/CIZU_NNAZsA?t=5665 As you can see in the video (if you maximize it, the text is small), you go into Xcode settings for your target, find "Other linker flags" and add See this horribly compressed screenshot: Again, whenever you see Update: I have since confirmed, if you have a static framework, you need to add |
@kpgalligan adding the I am now inclining towards, maybe it's an Xcode issue with Swift preview, regardless of Static or Dynamic framework, SwiftUI just breaks with KMM. Don't think it's down to SQL even anymore, its just any other framework causes preview to fail |
For SwiftUI previews, I'm told you need dynamic frameworks, although I'd definitely say I'm no expert there. If you use SQLDelight and a dynamic framework from Kotlin, you shouldn't need to add |
I just had this issue in the new project I started, and all I had to do was what Kevin said, add |
@kpgalligan You can set up it as static if you know what it means under the hood. But the recommended way is to pass linker flags to the compiler in an ios app build setting. |
Add
If you encounter the following problems:
Change your
|
Or add it to your ios target: ios {
binaries.framework {
baseName = project.name
compilations.all {
kotlinOptions.freeCompilerArgs += arrayOf("-linker-options", "-lsqlite3")
}
}
} |
Solution mentioned here worked for me: I added libsqlite3.tbd in the Target Setting->Build Phase->Link Binary with Libraries |
My annual reminder that this is just a linker issue. It is expected. Adding the linker flag isn't a "workaround". It's how linking works. In reference to the solution from @whataa target 'iosApp' do
pod 'sqlite3', '~> 3.42.0' // choose your version
end I haven't tried this, but you should check if you're actually building your own sqlite binary. The iPhone has a sqlite library that you can link to. Building your own will "work", but you'll have a fair bit of binary in your app that you don't need. Anyway, wherever you see:
It's the linker saying it can't find sqlite3. That is always the issue, and the most straightforward answer is always to tell the linker to use the system sqlite3 library by adding |
XCode > Build Phases > Link Binary With Libraries > and adding the libsqlite3.tbd |
(Taps the sign...) XCode > Build Settings > "Other Linker Flags" Add That is the answer. If you're using the sqlite shipped with all Apple platforms, you need to link to it. Period. |
I got it solved by turning static linking off in the shared module. listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = false
}
} I found this from https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-ktor-sqldelight.html#create-the-ios-application It says and I quote
|
That's not a good solution from the "official" docs. There are legitimate reasons to not want a dynamic framework. Again, it is always
I generally default to static frameworks. Many apps do as well. I'll ping JetBrains about their docs. Update: Cool, you can actually fork the docs and submit a PR. Hmm... |
I had a similar issue. Multimodule KMP project, some nested modules, one of which uses I was already applying // data/database/build.gradle.kts
sqldelight {
linkSqlite = true
// other config...
} But this didn't work when building for release (via Xcode -> Product -> Archive). I applied the same // shared/build.gradle.kts
sqldelight {
linkSqlite = true
} |
linkSqlite = true and Adding -lsqlite3. |
Tried to use the kotlin native cocoapod gradle plugin. But it produces the error below whenever sqldelight is included as a dependency.
Undefined symbols for architecture arm64:
"_sqlite3_bind_text16", referenced from:
_SQLiter_SQLiteStatement_nativeBindString in app(combined.o)
"_sqlite3_bind_int64", referenced from:
_SQLiter_SQLiteStatement_nativeBindLong in app(combined.o)
"_sqlite3_last_insert_rowid", referenced from:
_SQLiter_SQLiteStatement_nativeExecuteForLastInsertedRowId in app(combined.o)
"_sqlite3_reset", referenced from:
_SQLiter_SQLiteConnection_nativeResetStatement in app(combined.o)
"_sqlite3_changes", referenced from:
_SQLiter_SQLiteStatement_nativeExecuteForChangedRowCount in app(combined.o)
_SQLiter_SQLiteStatement_nativeExecuteForLastInsertedRowId in app(combined.o)
"_sqlite3_open_v2", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_db_config", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_busy_timeout", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_trace", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_bind_parameter_index", referenced from:
_SQLiter_SQLiteConnection_nativeBindParameterIndex in app(combined.o)
"_sqlite3_column_bytes", referenced from:
_SQLiter_SQLiteConnection_nativeColumnGetString in app(combined.o)
_SQLiter_SQLiteConnection_nativeColumnGetBlob in app(combined.o)
"_sqlite3_finalize", referenced from:
_SQLiter_SQLiteStatement_nativeFinalizeStatement in app(combined.o)
"_sqlite3_column_text", referenced from:
_SQLiter_SQLiteConnection_nativeColumnGetString in app(combined.o)
"_sqlite3_column_name", referenced from:
_SQLiter_SQLiteConnection_nativeColumnName in app(combined.o)
"_sqlite3_bind_double", referenced from:
_SQLiter_SQLiteStatement_nativeBindDouble in app(combined.o)
"_sqlite3_profile", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_close", referenced from:
_SQLiter_SQLiteConnection_nativeClose in app(combined.o)
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_prepare16_v2", referenced from:
_SQLiter_SQLiteConnection_nativePrepareStatement in app(combined.o)
"_sqlite3_column_type", referenced from:
_SQLiter_SQLiteConnection_nativeColumnIsNull in app(combined.o)
_SQLiter_SQLiteConnection_nativeColumnType in app(combined.o)
"_sqlite3_column_count", referenced from:
_SQLiter_SQLiteConnection_nativeColumnCount in app(combined.o)
"_sqlite3_bind_blob", referenced from:
_SQLiter_SQLiteStatement_nativeBindBlob in app(combined.o)
"_sqlite3_db_readonly", referenced from:
_SQLiter_SQLiteConnection_nativeOpen in app(combined.o)
"_sqlite3_column_int64", referenced from:
_SQLiter_SQLiteConnection_nativeColumnGetLong in app(combined.o)
"_sqlite3_bind_null", referenced from:
_SQLiter_SQLiteStatement_nativeBindNull in app(combined.o)
"_sqlite3_extended_errcode", referenced from:
android::throw_sqlite3_exception(sqlite3*) in app(combined.o)
android::throw_sqlite3_exception(sqlite3*, char const*) in app(combined.o)
"_sqlite3_column_double", referenced from:
_SQLiter_SQLiteConnection_nativeColumnGetDouble in app(combined.o)
"_sqlite3_column_blob", referenced from:
_SQLiter_SQLiteConnection_nativeColumnGetBlob in app(combined.o)
"_sqlite3_step", referenced from:
_SQLiter_SQLiteConnection_nativeStep in app(combined.o)
_SQLiter_SQLiteStatement_nativeExecute in app(combined.o)
_SQLiter_SQLiteStatement_nativeExecuteForChangedRowCount in app(combined.o)
_SQLiter_SQLiteStatement_nativeExecuteForLastInsertedRowId in app(combined.o)
"_sqlite3_clear_bindings", referenced from:
_SQLiter_SQLiteConnection_nativeClearBindings in app(combined.o)
"_sqlite3_errmsg", referenced from:
android::throw_sqlite3_exception(sqlite3*) in app(combined.o)
android::throw_sqlite3_exception(sqlite3*, char const*) in app(combined.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The text was updated successfully, but these errors were encountered: