无法在 XCode 中使用 Cocoapods 归档 Kotlin Native
Unable to archive Kotlin Native with Cocoapods in XCode
我尝试在 XCode12 中归档一个引用带有 cocoapods 插件的 Kotlin Native 框架的项目,但失败并显示如下消息(使用 iPhone SE 构建归档文件)
Ignoring file *MyFramework*, building for iOS-armv7 but attempting to link with file built for iOS-arm64
Undefined symbol: _OBJC_CLASS_$_... (for armv7)
我在项目的 Podfile 中将我的框架引用为本地 pod(使用 :path
和 :modular_headers => true
)
据我所知,我必须构建一个包含 armv7
和 arm64
的胖框架,但如何使用 Kotlin cocoapods
插件来管理它?
这里有一些带有推荐的链接,但我无法将它们放在一起用于我的案例
https://github.com/ilmat192/kotlin-native-gradle-samples/blob/master/fat-framework/build.gradle.kts
https://github.com/JetBrains/kotlin-native/issues/3140
https://medium.com/@yuyaHorita/universal-frameworks-xcframework-with-kotlinnative-999d830e206e
https://github.com/JetBrains/kotlin-native/issues/2574
https://github.com/ilmat192/kotlin-native-gradle-samples/blob/master/fat-framework/build.gradle.kts
项目的build.gradle
buildscript {
ext.kotlinVersion = '1.4.20-M2'
// use 1.3.7 to avoid iOS build error
// "Deserializer for declaration public kotlinx.coroutines/SingleThreadDispatcher|null[0] is not found"
ext.coroutinesVersion = '1.3.7'
ext.ktorVersion = '1.4.1'
ext.napierVersion = '1.4.0'
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
repositories {
google()
jcenter()
}
Molule 的 build.gradle
plugins {
id 'org.jetbrains.kotlin.multiplatform' version "$kotlinVersion"
id "org.jetbrains.kotlin.native.cocoapods" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlinVersion"
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/aakira/maven" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId 'org.jetbrains.kotlin.mpp_app_android'
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
kotlin {
android("android")
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
// https://kotlinlang.org/docs/reference/mpp-dsl-reference.html#native-targets
fromPreset(iOSTarget, 'ios') {
binaries {
}
}
}
// CocoaPods requires the podspec to have a version.
version = "1.0"
cocoapods {
// Configure fields required by CocoaPods.
def projectName = project.getRootProject().getName()
summary = projectName
homepage = "https://ya.ru"
ios.deploymentTarget = "9.0"
frameworkName = projectName
pod("NVHTarGzip")
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.9.1")
// Coroutines components
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
// workaround https://youtrack.jetbrains.com/issue/KT-41378
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt-2")
// Ktor components
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-network:$ktorVersion")
// workaround https://github.com/AAkira/Napier/issues/48
implementation "com.github.aakira:napier:1.4.1-alpha1"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
// Ktor components
implementation("io.ktor:ktor-client-android:$ktorVersion")
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.9.1")
// Ktor components
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
iosTest {
}
}
}
解决方案
实际上不是真正的解决方案 - 基于我刚刚放弃的已接受答案 armv7
支持将其添加到 Excluded Architectures
building for iOS-armv7 but attempting to link with file built for iOS-arm64
看起来您正在尝试为 armv7 存档,(我认为)它是 32 位 ios,或者 watch 等。大多数应用只需要 arm64 和您的 Xcode 框架根据这个只会是 arm64:
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
如果您只需要 arm64,并且它只是一个 iOS 应用程序,这似乎很可能,您可以在构建中禁用 armv7 架构。或者,您可以尝试组合 ios()
目标。
我们这里有一个功能示例:https://github.com/touchlab/KaMPKit
它使用的是 cocoapods 插件的一个分支,但除了 isStatic
,它基本上是相同的插件。
我尝试在 XCode12 中归档一个引用带有 cocoapods 插件的 Kotlin Native 框架的项目,但失败并显示如下消息(使用 iPhone SE 构建归档文件)
Ignoring file *MyFramework*, building for iOS-armv7 but attempting to link with file built for iOS-arm64
Undefined symbol: _OBJC_CLASS_$_... (for armv7)
我在项目的 Podfile 中将我的框架引用为本地 pod(使用 :path
和 :modular_headers => true
)
据我所知,我必须构建一个包含 armv7
和 arm64
的胖框架,但如何使用 Kotlin cocoapods
插件来管理它?
这里有一些带有推荐的链接,但我无法将它们放在一起用于我的案例
https://github.com/ilmat192/kotlin-native-gradle-samples/blob/master/fat-framework/build.gradle.kts
https://github.com/JetBrains/kotlin-native/issues/3140
https://medium.com/@yuyaHorita/universal-frameworks-xcframework-with-kotlinnative-999d830e206e
https://github.com/JetBrains/kotlin-native/issues/2574
https://github.com/ilmat192/kotlin-native-gradle-samples/blob/master/fat-framework/build.gradle.kts
项目的build.gradle
buildscript {
ext.kotlinVersion = '1.4.20-M2'
// use 1.3.7 to avoid iOS build error
// "Deserializer for declaration public kotlinx.coroutines/SingleThreadDispatcher|null[0] is not found"
ext.coroutinesVersion = '1.3.7'
ext.ktorVersion = '1.4.1'
ext.napierVersion = '1.4.0'
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
repositories {
google()
jcenter()
}
Molule 的 build.gradle
plugins {
id 'org.jetbrains.kotlin.multiplatform' version "$kotlinVersion"
id "org.jetbrains.kotlin.native.cocoapods" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlinVersion"
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/aakira/maven" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId 'org.jetbrains.kotlin.mpp_app_android'
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
kotlin {
android("android")
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
// https://kotlinlang.org/docs/reference/mpp-dsl-reference.html#native-targets
fromPreset(iOSTarget, 'ios') {
binaries {
}
}
}
// CocoaPods requires the podspec to have a version.
version = "1.0"
cocoapods {
// Configure fields required by CocoaPods.
def projectName = project.getRootProject().getName()
summary = projectName
homepage = "https://ya.ru"
ios.deploymentTarget = "9.0"
frameworkName = projectName
pod("NVHTarGzip")
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.9.1")
// Coroutines components
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
// workaround https://youtrack.jetbrains.com/issue/KT-41378
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt-2")
// Ktor components
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-network:$ktorVersion")
// workaround https://github.com/AAkira/Napier/issues/48
implementation "com.github.aakira:napier:1.4.1-alpha1"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
// Ktor components
implementation("io.ktor:ktor-client-android:$ktorVersion")
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.9.1")
// Ktor components
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
iosTest {
}
}
}
解决方案
实际上不是真正的解决方案 - 基于我刚刚放弃的已接受答案 armv7
支持将其添加到 Excluded Architectures
building for iOS-armv7 but attempting to link with file built for iOS-arm64
看起来您正在尝试为 armv7 存档,(我认为)它是 32 位 ios,或者 watch 等。大多数应用只需要 arm64 和您的 Xcode 框架根据这个只会是 arm64:
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
如果您只需要 arm64,并且它只是一个 iOS 应用程序,这似乎很可能,您可以在构建中禁用 armv7 架构。或者,您可以尝试组合 ios()
目标。
我们这里有一个功能示例:https://github.com/touchlab/KaMPKit
它使用的是 cocoapods 插件的一个分支,但除了 isStatic
,它基本上是相同的插件。