magnumrocha
04/13/2020, 11:39 AMCOpaquePointer
?
in Swift we can do something like:
var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
<http://context.info|context.info> = Unmanaged<Reachability>.passUnretained(self).toOpaque()
where self
is a the Swift class that contain this code...Kavan
04/14/2020, 12:21 PMdazza5000
04/14/2020, 8:30 PMantrax
04/14/2020, 9:26 PMantrax
04/14/2020, 9:29 PMfelislynx
04/15/2020, 6:57 AMRupesh
04/15/2020, 11:18 AMval startCommand = "adb shell am start -S -W $appPackage/$launchActivity -c android.intent.category.LAUNCHER -a android.intent.action.MAIN"
Runtime.getRuntime().exec("$startCommand")
But when I tried to write log into file its not:
val writeLog = "adb logcat -d | grep --line-buffered ABC >> logcat.txt"
Runtime.getRuntime().exec("$writeLog")
Alexander Larsson
04/16/2020, 8:06 AMcinterop
to call functions in the OpenSSL library. We already had it compiled as a .framework
for iOS (calling fron Obj-C) so we re-used now when we are trying to call from Kotlin. We have managed to build a .klib
using Gradle.
From `build.gradle.kts`:
val ios = iosArm64("ios")
val iosSim = iosX64("iosSim")
configure(listOf(iosSim, ios)) {
binaries.framework {
baseName = frameworkBaseName
}
compilations {
val main by getting {
cinterops {
val openssl by creating {
defFile("$projectDir/src/iosMain/cinterop/openssl.def")
includeDirs("$projectDir/src/iosMain/cinterop/OpenSSL-Apple/include")
}
}
}
}
Def file:
headers = openssl/asn1.h openssl/err.h openssl/pkcs12.h openssl/rsa.h openssl/x509.h
staticLibraries = openssl
libraryPaths = <beginning of absolute path>/KotlinMultiplatformTestSDK/shared/src/iosMain/cinterop/OpenSSL-Apple/frameworks/iPhone/openssl.framework
The above configuration works and produces a klib
and we can then go ahead and import it and try to make a call to OpenSSL from Kotlin:
package openssl
import interop.*
import kotlinx.cinterop.*
class TestOpenSSL {
fun TestOpenSSL_init() {
ERR_load_crypto_strings()
}
}
We get code completion and everything seems to work just fine until we build it and we get an error from the linker:
> Task :shared:linkDebugFrameworkIos
v: Using Kotlin home directory dist/kotlinc
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
Undefined symbols for architecture arm64:
"_ERR_load_crypto_strings", referenced from:
_openssl_ERR_load_crypto_strings_wrapper662 in result.o
ld: symbol(s) not found for architecture arm64
> Task :shared:linkDebugFrameworkIos FAILED
Any ideas whats wrong here? How do we get this working? Would really appreciate any help! 🙂Alexander Larsson
04/16/2020, 1:15 PMmagnumrocha
04/16/2020, 4:19 PMstaticCFunction{..}
helper function from Kotlin/Native to wrap a Kotlin lambda function into a C function pointer. It only allows having unbound and non-capturing lambda functions. For example, it is not able to use a local variable from the function. We may only use globally visible declarations."
"globally visible declarations" -> how can access my global kotlin declarations inside the the lambda of staticCFunction
, because I have tested some approaches and only could have access to functions that use kotlin global functions (like println
), if I use some of my global scoped declarations my code fails on kotlin native call stack...Kavan
04/17/2020, 5:04 AMgabin
04/17/2020, 11:00 AMgabin
04/17/2020, 11:01 AMDaniel Rampelt
04/17/2020, 2:41 PM> Task :shared:linkDebugFrameworkIos FAILED
e: /Users/.../project/shared/some/module/build/classes/kotlin/ios/main/module1 is cached (in /Users/.../.konan/kotlin-native-macos-1.3.72/klib/cache/ios_x64-gSTATIC/libmodule1-cache.a), but its dependency isn't: /Users/.../project/shared/module2/build/classes/kotlin/ios/main/module2
Alexander Larsson
04/17/2020, 2:47 PMBenjamin Charais
04/17/2020, 10:17 PMPeter Samokhin
04/18/2020, 3:55 AMtargetFromPreset(presets["iosX64"], "iosX64") { compilations["main"].source(sourceSets["nativeMain"]) }
i.e. when I have the only one sources directory for a lot of different native targets,
and when I try to create only one actual class. In this case, there is a really annoying IDE error with the suggestion to create N
actual declarations instead of the only one.hannesstruss
04/18/2020, 7:10 PMQuery<RowType>
). @russhwolf suggested using a top level func like func createPublisher<T>(query: RuntimeQuery<T>) -> AnyPublisher<RuntimeQuery<T>, Never>
. That works! Are there maybe any other solutions?saket
04/19/2020, 4:18 PMInvalidMutabilityException
on native platforms because they use lazy{}
values. My code is single threaded and does not freeze objects anywhere. Are test graphs frozen by default on native platforms?
update: TIL objects
are frozen by default!mbonnin
04/19/2020, 10:18 PMCPointer
always 64bits in RAM or is it refcounted ? What's in the "header" ? refcount ? frozen state ? other ?napperley
04/20/2020, 1:37 AMAlexander Larsson
04/20/2020, 8:22 AMFoundation
. The cinterop
task fails with an exception:
> Task :shared:cinteropObjektiveSSLIos FAILED
1 actionable task: 1 executed
Exception in thread "main" java.lang.Error: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1: error: expected identifier or '('
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:1003)
at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:992)
at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:230)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:46)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:44)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':shared:cinteropObjektiveSSLIos'.
> Process 'command '/Applications/IntelliJ IDEA <http://CE.app/Contents/jbr/Contents/Home/bin/java|CE.app/Contents/jbr/Contents/Home/bin/java>'' finished with non-zero exit value 1
Line 492 in NSObjCRuntime.h is:
@class NSString, Protocol;
Is this a bug in Kotlin/Native or the cinterop
tool?
I can remove the import of Foundation
to "fix" this bug but then it fails with error: unknown type name 'NSData'
so I obviously need to keep it in there.
Any workarounds?Alexander Larsson
04/20/2020, 11:59 AMSomeClass.staticMethod()
.Romain Dubreucq
04/20/2020, 2:08 PMPatrick
04/20/2020, 2:40 PMpackage sample
import io.ktor.client.HttpClient
import io.ktor.client.engine.curl.Curl
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.client.request.get
import kotlinx.coroutines.runBlocking
fun main() = runBlocking<Unit> {
val client = HttpClient(Curl) {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
val response = client.get<String>("<http://google.de>")
println(response)
}
However the linker fails with this error message: C:\Users\Patrick\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: cannot find -lcurl
- This tells me that curl seems to be missing. However it should be installed on Windows 10 by default. I also downloaded the curl binaries and added them to the include path, but still nothing. Any ideas why the linker fails here?Ian Stewart
04/20/2020, 5:05 PMkpgalligan
04/20/2020, 6:26 PM./gradlew dependencies:update
fails with
A problem occurred evaluating project ':backend.native:tests'.
> Could not resolve all files for configuration ':backend.native:tests:update_tests'.
> Could not resolve org:Kotlin_KotlinRelease_1370_Compiler:1.3.72-eap-463.
Required by:
project :backend.native:tests
> Could not resolve org:Kotlin_KotlinRelease_1370_Compiler:1.3.72-eap-463.
> Could not get resource '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1370_Compiler/1.3.72-eap-463/teamcity-ivy.xml>'.
> Could not GET '<https://buildserver.labs.intellij.net/guestAuth/repository/download/Kotlin_KotlinRelease_1370_Compiler/1.3.72-eap-463/teamcity-ivy.xml>'. Received status code 400 from server: Bad Request
I’ve seen similar issues in the past. Running ./gradlew dependencies:update
for master seems to work fine.delblanco
04/22/2020, 10:39 AMsuspend
isn't available in swift. In my example I created this fairly simple `UserRepository`:
interface UserRepository {
suspend fun getUser(uri: UserUri) : User
suspend fun getUsers() : List<User>
fun getUsersIosWorkaround() : List<User>
}
On jvm/android all three methods are available though when compiling for iOS the last non suspend function is available. This is the converted protocol as found in `common.h`:
__attribute__((swift_name("UserRepository")))
@protocol CommonUserRepository
@required
- (NSArray<CommonUser *> *)getUsersIosWorkaround __attribute__((swift_name("getUsersIosWorkaround()")));
@end;
They're also missing on the dummy UserRepository implementation inside `common.h`:
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("MockUserRepository")))
@interface CommonMockUserRepository : CommonBase <CommonUserRepository>
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
- (NSArray<CommonUser *> *)getUsersIosWorkaround __attribute__((swift_name("getUsersIosWorkaround()")));
@end;
Presenters definied in common
can invoke the suspend functions so I know they work in the PoC app.
Not sure if this is a bug, bad configuration or by design.. so any help is appreciated!Nikolay Kasyanov
04/22/2020, 2:21 PMvalues()
in each enum class
, although it doesn’t seem to be exposed to Objective-C headers. Is this a known limitation?kevin.cianfarini
04/22/2020, 6:29 PM