louiscad
03/08/2024, 11:43 AMLoïc Lamarque
03/08/2024, 1:43 PMNotBlankString
explicit type that you’ve dreamed of. 🙌
What’s more? This type uses kotlinx.serialization for automatic conversion from or as String
. 🤯
Want more? Check Kotools Types on GitHub. 👀Evghenii
03/08/2024, 4:54 PMclass MyClass(dispatcher: CoroutineDispatcher = Dispatchers.Default) {
private val scope = CoroutineScope(dispatcher)
fun start() {
scope.launch {
while (true) {
// do stuff
delay(1000L)
}
}
scope.launch {
OtherObject.someSharedFlow.collect {
ThirdObject.doSomeStuff()
}
}
}
}
private val testSharedFlow = MutableSharedFlow<SomeEvent>()
@Test
fun someTest() = runTest {
mockkObject(OtherObject)
every { OtherObject.someSharedFlow } returns testSharedFlow.asSharedFlow()
mockkObject(ThirdObject)
every { ThirdObject.doSomeStuff() } answers {}
val myClass = MyClass(StandardTestDispatcher(testScheduler))
myClass.start()
testSharedFlow.emit(SomeEvent()).also {
verify { ThirdObject.doSomeStuff() } // this fails
}
unmockkObject(ThirdObject)
unmockkObject(OtherObject)
}
Evghenii
03/08/2024, 4:55 PMAkram Raza
03/08/2024, 5:06 PMEvghenii
03/08/2024, 5:07 PMAkram Raza
03/08/2024, 5:16 PMEvghenii
03/08/2024, 5:16 PMAkram Raza
03/08/2024, 5:20 PMEvghenii
03/08/2024, 5:22 PMAkram Raza
03/08/2024, 5:24 PMmuhmmed alsadig
03/09/2024, 5:26 PMPatrick Cavanagh
03/09/2024, 5:28 PMursus
03/09/2024, 7:33 PMRizky Agung Prayogi
03/11/2024, 8:03 AMElawsDev
03/11/2024, 11:22 AMFred Bowker
03/11/2024, 2:05 PMFred Bowker
03/11/2024, 2:27 PM0xf1f1
03/12/2024, 7:10 PMobject Route {
val route = "sss"
object LogOn {
override val icon = Icons.Filled.AccountBox
override val path = "/login"
}
}
Huy Diep
03/13/2024, 1:43 PMHuy Diep
03/13/2024, 1:46 PMrkeazor
03/13/2024, 10:12 PMpp.amorim
03/14/2024, 3:07 PMBuildConfig._DEBUG_
is false. While it’s possible in Swift, I can’t do the same in Kotlin. (at least with what I know) I am doing some code migration and it would be terrible to have it going to production without fixing itLuca Nicoletti
03/14/2024, 3:50 PMpp.amorim
03/15/2024, 12:18 AMe: java.lang.AssertionError: Unbound symbols not allowed
Unbound private symbol IrSimpleFunctionSymbolImpl: invisible_fake final fun `<set-view>`(`<set-?>`: T?): kotlin.Unit defined in ...CoroutinePresenter.Impl[PropertySetterDescriptorImpl@506d6705]
at org.jetbrains.kotlin.ir.util.SymbolTableKt.noUnboundLeft(SymbolTable.kt:1141)
at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:96)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:194)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:53)
....
noUnboundLeft
is odd.Hasan Tunçay
03/15/2024, 12:21 PMMarc Planas
03/18/2024, 9:53 AMMárton Matusek
03/18/2024, 11:02 AMLavish Swarnkar
03/18/2024, 12:57 PMval expression = // Input expression by user
val a, b = // Input Ints by user
val script = "fun x(a: Int, b: Int) = $expression; x($a, $b)
// Run script using KotlinScriptEngine
While running this app, I get a runtime error :
Accessing hidden field Lsun/security/util/SecurityConstants;->GET_CLASSLOADER_PERMISSION:Ljava/lang/RuntimePermission; (unsupported, linking, allowed)
W Accessing hidden method Lsun/misc/Unsafe;->getAndAddInt(Ljava/lang/Object;JI)I (max-target-r, reflection, denied)
W Accessing hidden method Lsun/misc/Unsafe;->getAndAddInt(Ljava/lang/Object;JI)I (max-target-r, reflection, denied)
W javax.script.ScriptException: ERROR Unable to initialize repl compiler:
W ERROR java.lang.NoSuchMethodException: getAndAddInt [class java.lang.Object, long, int]: java.lang.Error: java.lang.NoSuchMethodException: getAndAddInt [class java.lang.Object, long, int]: java.lang.IllegalStateException: Unable to initialize repl compiler:
W ERROR java.lang.NoSuchMethodException: getAndAddInt [class java.lang.Object, long, int]: java.lang.Error: java.lang.NoSuchMethodException: getAndAddInt [class java.lang.Object, long, int]
W at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.asJsr223EvalResult(KotlinJsr223JvmScriptEngineBase.kt:104)
• After research I found out that starting A12 several such Non-SDK references getAndAddInt()
have been blocked (Reference)
• I think the Kotlin Compiler is not working on Android. In fact, I found an OPEN Kotlin issue raised for this. But people have succeeded in doing this. Here are 2 Android apps that compile and execute Kotlin code on device : 1. Offline Kotlin IDE 2. Code Assist (Android Studio for Android)
Code Info
• I’m using 34 targetSdk, so non-SDK ref blocked in A12 (SDK 30) won’t work. But one of the apps that work - Code Assist (mentioned above), uses 32 targetSdk, still it works for them (reference).
• Gradle Dependencies used : (Complete code)
implementation("io.apisense:rhino-android:1.0")
implementation(kotlin("scripting-jsr223"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
runtimeOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable")
• Simplified code that executes the script : (Complete code)
import javax.script.ScriptEngineManager
val engineManager = ScriptEngineManager()
val engine = engineManager.getEngineByExtension("kts")
engine.eval(kotlinCode)
This is just a simplified example, if this works - I have bigger usecase in mind. Any help in making this work is highly appreciated. Thank you for your time!Demis
03/18/2024, 10:10 PM