我已经按照https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html的教程进行操作,我想对我在 SharedModule 中创建的 commonTest 进行单元测试。
我尝试过的事情:
我曾尝试在公共文件中使用 kotlin.test。我在网上查到可以使用JUnit5,但是当我在commonTest中导入依赖项时,我无法访问kotlin.test的库。现在我已经成功地在 commonTest 中实现了 kotlin.test 但是我该如何运行它呢?
我试过 gradlew commonTest.kt 但它不起作用。请帮忙谢谢!
我的 SharedModule gradle 代码:
apply plugin: 'kotlin-multiplatform'
kotlin {
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'iOS') {
binaries {
framework('SharedCode')
}
}
fromPreset(presets.jvm, 'android')
}
sourceSets {
commonMain.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
api 'org.jetbrains.kotlin:kotlin-stdlib'
//implementation("com.ionspin.kotlin:bignum:0.0.8")
//Testing
//implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
//implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
/*
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"*/
}
commonTest.dependencies{
//implementation ("org.junit.jupiter:junit-jupiter-api:5.2.0")
//implementation ("org.junit.jupiter:junit-jupiter-engine:5.0.3")
//implementation 'junit:junit:4.12'
implementation …Run Code Online (Sandbox Code Playgroud) 我正在从事Kotlin多平台项目。我使用Ktor客户端进行网络调用。我想根据一些不基于响应头的自定义逻辑缓存一些请求。
HttpCache提供的功能Ktor是响应头驱动的,我无法覆盖它,因为类的数量是Internal.
如何启用Ktor自定义缓存?
使用 Android Studio 的“转到声明”功能(cmd + 单击)时,会显示反编译的源代码,尽管源代码在我的项目中。kotlin MP 源在另一个模块中。我可以使用“选择源...”选项连接源,但是我必须为每个文件执行此操作。是否有用于连接到正确源文件的全局修复?
当我切换构建变体时,出现编译错误,但问题仅适用于非默认构建变体(debug & release)。因此,如果我定义customBuild { }然后选择那个,它就会失败并显示以下错误日志:
The consumer was configured to find a runtime of a component,
preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr'
with value 'customBuild', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'.
However we cannot choose between the following variants of project :shared-module:
- iosArm64RuntimeOnly
- iosX64RuntimeOnly
All of them match the consumer attributes:
- Variant 'iosArm64RuntimeOnly' capability ExampleApp:shared-module:1.0:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'customBuild')
- Doesn't say anything about …Run Code Online (Sandbox Code Playgroud) android gradle-kotlin-dsl kotlin-multiplatform kotlin-multiplatform-mobile
在 Xcode 中使用 KMM 共享库时,在 Xcode 中构建时会出现多个警告
首先,让我解释一下我做了什么,以便更好地理解我所做的事情以及我在使用 Xcode 构建共享 KMM 库时遇到的一些问题。
我在我的 Windows PC 上使用 Android Studio 创建了一个 Android 项目,适用于手机、电视和穿戴设备,这三个设备都使用共享模块。我还想构建一个 iOS 应用程序,因此我在 Mac 上使用 Android Studio 创建一个新的 KMM 应用程序。我已将共享模块添加到此 KMM 应用程序并开始构建 iOS 应用程序。成功后,我添加了一个在 Apple Watch 上运行的应用程序,因此我使用 Xcode 手动添加一个适用于 iOS 应用程序的手表应用程序(文件 -> 新建 -> 目标...)。我配置了它,做了一些基本的编码/管道,构建了它,一切都工作正常。
共享模块稍作更改,使其与 Xcode 结合使用 Android,我已将其添加到Podfile(我也在我的项目中使用 Firebase):
target 'XYZ' do
use_frameworks!
platform :ios, '15.0'
pod 'shared', :path => '../shared'
# add pods for desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods
pod 'Firebase/Messaging'
pod 'Firebase/Analytics'
pod 'Firebase/InAppMessaging' …Run Code Online (Sandbox Code Playgroud) LazyColumn和LazyRow正在替换旧 UI 中的RecyclerView ,但是当滚动RecyclerView中的项目并返回时,它会消失,然后回收到优化 UI。
LazyColumn 和 LazyRow 正在做同样的事情?
android kotlin kotlin-multiplatform android-jetpack android-jetpack-compose
我第一次使用 Android Studio 构建多平台项目。我创建了一个 Android 应用程序模块,该模块使用 Android 上的多平台库。我还使用 XCode 构建了一个 iOS 应用程序,该应用程序使用 iOS 上的多平台库。一切工作正常,我能够使用由不同的Android 和 iOSexpect fun实现的。actual fun
我还用 C++ 创建了一个公开 C 接口的库。
#ifndef PINGLIB_LIBRARY_H
#define PINGLIB_LIBRARY_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
long long elapsed;
} PingInfo;
typedef void (*PingCallback)(PingInfo pingInfo);
typedef struct
{
PingCallback pingUpdate;
} PingObserver;
void* ping(const char * url, const PingCallback *pingCallback);
void subscribe(void* pingOperation);
void unsubscribe(void* pingOperation);
#ifdef __cplusplus
}
#endif
#endif //PINGLIB_LIBRARY_H
Run Code Online (Sandbox Code Playgroud)
我使用 CLion 构建 C++ 代码。我创建了一个 …
目前是否可以有一个使用 compose 的 kotlin 多平台项目来同时共享桌面、Web 和移动设备的 ui 代码?我发现的所有示例仅涵盖带有 JS Front + Jvm Backend 或 JVM Android + Desktop + Common Module 的多平台,并且我在同时使用所有这些设置项目时遇到了麻烦。
我尝试这样做:
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose") version "1.0.1-rc2"
id("com.android.library")
}
kotlin {
android()
jvm("desktop") {
...
}
js{
...
}
sourceSets {
val commonMain by getting {
dependencies {
...
}
}
val commonTest by getting {
dependencies {
...
}
}
val androidMain by getting {
dependencies {
...
}
}
val androidTest by getting {
dependencies { …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Kotlin 多平台项目,该项目涉及用于数据提取的 HTML 解析。虽然我已经成功地将 Ktor 实现为 HTTP 客户端,但我仍在寻找与 Kotlin Multiplatform 兼容的可靠且高效的 HTML 解析解决方案。
您能否分享一些见解、最佳实践或任何非常适合在 Kotlin 多平台开发环境中进行 HTML 解析的库?我对在类似项目中被证明有效的经验和方法特别感兴趣。
在使用 Kotlin 多平台移动项目时,我在配置项目时收到此错误。特别是通过 Xcode 内的 iOS 默认脚本构建它时。
这是错误
> Configure project :HomeShared
Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.
The property 'kotlin.mpp.enableGranularSourceSetsMetadata=true' has no effect in this and future Kotlin versions, as Hierarchical Structures support is now enabled by default. It is safe to remove the property.
The property 'kotlin.native.enableDependencyPropagation=false' has no effect in this and future Kotlin versions, as Kotlin/Native dependency commonization is now enabled by default. …Run Code Online (Sandbox Code Playgroud) kotlin ×7
android ×5
ios ×2
c++ ×1
gradle ×1
kotlin-multiplatform-mobile ×1
ktor ×1
watchos ×1
web-scraping ×1
xcode ×1