Joey
04/21/2020, 3:49 AMZabGo
04/21/2020, 10:29 AMfun setContext(currentActivity: Activity){
connector.setUIContext(currentActivity) // this function is from the third party library
}
I wonder how I could access the type Activity. It looks it does not recognise it or the android api is not accessible.
Do I need to add anything in the build.gradle.kts?
Thanks for your helpdimsuz
04/21/2020, 12:54 PMmoko-resources
? Or doesn't bother and duplicates?kkovach
04/21/2020, 1:03 PMcurioustechizen
04/21/2020, 3:38 PMcommonMain
and iosMain
, I want to create a iosTest
folder that uses iOS-specific code for writing tests to be run on the simulator.
I've looked around but I think all the info I find is out-dated. What's the latest on this?Jess Brent
04/21/2020, 7:08 PMcom.whatever.whatever
for import statements one platform, but not another? i can’t really come up with the exact phrase to google here so i’m a little SoLsaket
04/22/2020, 4:59 AMcurioustechizen
04/22/2020, 7:57 AMandroidMain
and iosMain
implicitly depend on commonMain
. How about tests? Do androidTest
and iosTest
implicitly depend on commonTest
? This seems intuitive, but is it documented somewhere?gabin
04/22/2020, 2:48 PMJan Stoltman
04/22/2020, 3:40 PMdimsuz
04/22/2020, 4:49 PMkotlinOptions.jvmTarget = "1.8"
for android target? Without it I have an error:
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
I tried
android("android") {
compilations.main.kotlinOptions {
jvmTarget = "1.8"
}
}
And it doesn't work, gives a DSL error.Matt Toal
04/22/2020, 10:29 PMRak
04/23/2020, 3:10 PMSam Garfinkel
04/23/2020, 4:37 PMexpect
in the common and delegate to the Java library on the JVM, and other similar libraries on their respective platforms (like a swift library with the same capability on Mac/iOS, etc.). Is one better than the other?j.l.
04/23/2020, 7:28 PMSam Garfinkel
04/23/2020, 11:00 PMmbonnin
04/24/2020, 1:50 PMSooYoung
04/25/2020, 6:13 AMJoey
04/26/2020, 5:37 AMplugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.71'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.71'
}
repositories {
jcenter()
mavenCentral()
}
//apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
//android {
// compileSdkVersion 28
// buildTypes {
// release {
// minifyEnabled false
// }
// }
//}
kotlin {
// This is for iPhone emulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'ios') {
binaries {
framework("framework")
}
}
fromPreset(presets.jvm, 'android')
}
def ktor_version = "1.3.0-rc"
def serialization_version = "0.14.0"
def coroutines_version = "1.3.5"
def klock_version = "1.7.0"
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
implementation "com.soywiz.korlibs.klock:klock:$klock_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
implementation kotlin('stdlib')
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
}
iosTest {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
}
}
}
// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
def target = project.findProperty('kotlin.target') ?: 'ios'
dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask
doLast {
def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
def targetDir = getProperty('configuration.build.dir')
copy {
from srcFile.parent
into targetDir
include 'shared.framework/**'
include 'shared.framework.dSYM'
}
}
}
I also have enableFeaturePreview("GRADLE_METADATA")
but i couldn't resolve dependencies in my iosMain
. What am i missing here? ThanksDavide Giuseppe Farella
04/26/2020, 11:16 AMcommandline
) cannot resolve dependencies from other multiplatform modules ( my source code only ) anymore.
For example I got a domain
like
kotlin {
jvm()
js()
sourceSets {
val commonMain by getting {
dependencies {
api(`kotlin-common`)
api(`coroutines-core-common`)
}
}
val jvmMain by getting {
dependencies {
api(`kotlin-jdk8`)
api(`coroutines-core`)
}
}
}
}
and got commandline
like
kotlin {
sourceSets {
val main by getting {
dependencies {
implementation(project(":domain")
}
}
}
}
But it can resolve all the dependencies exposed by api
in domain ( kotlin, coroutines, koin, etc ), but cannot resolve from my sourceSet ( like my.project.domain.MyClass
)
For some reason it was working before, I think it stopped to work after I added an android module ( which, differently from commainline
, it’s working flawlessly )
#FYI: I got enableFeaturePreview("GRADLE_METADATA")
Javier
04/26/2020, 4:50 PMTask 'test' not found in root project 'MyRootProject'
, But I can run jvmTest via IntelliJ without problemsAmanjeet Singh
04/27/2020, 5:07 AMcommonMain
using coroutines. Normally, the methods in android would be marked by suspend
and then they can fetch any data from remote or local. Also writing tests to this on JVM (Android in my case) is easy as we can create a runBlocking
and assert the results. But when it comes to iOS we don't have any suspend
methods and thus the same function cannot be tested and thus we end up adding a high order function which will give you an onSuccess
or onFailure
when launch
coroutine gives result.
This seems to be a bit messy to me because in common we end up maintaining 2 implementations for fetching same data each for android and iOS. (common is not "common" anymore in this case)
I need an approach which can be directly exposed to both worlds with unit tests also working on both sides. How you guys create repositories and unit test them? Advices and approaches would be appreciated 🙂Victor Grigorev
04/27/2020, 9:52 AMUndefined symbols for architecture arm64:
"_OBJC_CLASS_$_IosCombinedDialogModelAlign", referenced from:
objc-class-ref in StringExtensions.o
"_OBJC_CLASS_$...
...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What I need to do?Sean Keane
04/27/2020, 2:45 PMZabGo
04/27/2020, 3:09 PMbuildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
build.gradle(module)
plugins {
kotlin("multiplatform")
}
Kotlin{
iosX64("ios"){
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("io.ktor:ktor-client-core:1.3.2")
implementation("io.ktor:ktor-client-json:1.3.2")
implementation("io.ktor:ktor-client-serialization:1.3.2")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("io.ktor:ktor-client-android:1.3.2")
}
sourceSets["iosMain"].dependencies{
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("io.ktor:ktor-client-ios:1.3.2")
implementation("io.ktor:ktor-client-json-native:1.3.2")
implementation("io.ktor:ktor-client-serialization-native:1.3.2")
}
}Shawn Karber_
04/27/2020, 3:24 PMfun convertHexToBitString(dataString: String) : String {
val binaryArray: MutableList<String> = arrayListOf()
dataString.toCharArray().forEach {
val binValue =
if (it.isDigit()) {
String.format("%4s",
Integer.toBinaryString(Character.getNumericValue(it)))
.replace(' ', '0')
} else {
when(it.toUpperCase()) {
'A' -> "1010"
'B' -> "1011"
'C' -> "1100"
'D' -> "1101"
'E' -> "1110"
'F' -> "1111"
else -> "Invalid hexadecimal digit in string."
}
}
binaryArray.add(binValue)
}
return binaryArray.joinToString("")
it.isDigit() is not working in common.kt, nor is Character.getNumericValue, and neither is String.format(). Are any of these accessible through another means in Kotlin Multiplatform?Madhan
04/27/2020, 4:08 PMedenman
04/27/2020, 8:27 PMval Char.isEmoji: Boolean
helper? The Char api is pretty limited and all my stackoverflow results are jvm or iOS specificmbonnin
04/27/2020, 11:06 PMSystem.getProperty("user.dir")
on the JVM ?curioustechizen
04/28/2020, 9:06 AMresumeWith
on kotlin.coroutines.Continuation
a mutating operation? If so, how can I share it with another thread in order to bridge callback-style APIs and suspend functions?
My scenario: I have a suspend function in a shared API (shared between Android and iOS). On Android I just implement it as a regular suspend function. On iOS, I'm attempting to use continuation
and call it from my callback.
• If I freeze the continuation object I receive InvalidMutabilityException
,
• if I don't freeze it, I receive IncorrectDereferenceException
.
I'm using coroutines 1.3.5-native-mt