Error adding CocoaPods dependency in Kotlin Multiplatform - ios

I'm trying to setup a KMM module with Couchbase Lite as a platform dependency for both Android and iOS. I'm running into errors getting this to work with CocoaPods for iOS:
Exception in thread "main" java.lang.Error: /var/folders/pv/3_5xn0dd0v5bf6sxbfcsq_wr0000gn/T/7009311365357251921.m:1:22: error: expected ';' after module name
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
The generated 7009311365357251921.m file is not present at that path afterwards, which makes this difficult to debug.
build.gradle.kts:
plugins {
kotlin("multiplatform") version "1.4.21"
kotlin("native.cocoapods") version "1.4.21"
id("com.android.library")
}
...
kotlin {
android()
ios()
cocoapods {
summary = "TBD"
homepage = "TBD"
ios.deploymentTarget = "9.0"
pod("CouchbaseLite-Enterprise") {
version = "~> 2.8.1"
}
}
...
}
...
I get a different error if I use the non-enterprise release. Same build.gradle.kts except with pod("CouchbaseLite"). I get the error:
Exception in thread "main" java.lang.IllegalArgumentException: 'CBLQueryMeta' is going to be declared twice
at org.jetbrains.kotlin.native.interop.gen.KotlinFile.<init>(KotlinCodeModel.kt:257)
at org.jetbrains.kotlin.native.interop.gen.StubIrBridgeBuilder$kotlinFile$1.<init>(StubIrBridgeBuilder.kt:44)
at org.jetbrains.kotlin.native.interop.gen.StubIrBridgeBuilder.<init>(StubIrBridgeBuilder.kt:46)
at org.jetbrains.kotlin.native.interop.gen.StubIrDriver.run(StubIrDriver.kt:122)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:315)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
Both these pod specs compile without problem in an Xcode project. But Kotlin native seems to run into issues with them.
Update:
The pod("CouchbaseLite") error seems to be caused by having both a CBLQueryMeta and CBLQuery interface defined. There's a YouTrack issue for this. This error will likely still be a problem with CouchbaseLite-Enterprise, if the original error could be resolved.
Update 2:
If I remove the { version = "~> 2.8.1" } or put it in the function call directly pod("CouchbaseLite-Enterprise", "~> 2.8.1") I get a different error:
Exception in thread "main" java.lang.Error: /var/folders/pv/3_5xn0dd0v5bf6sxbfcsq_wr0000gn/T/6649487835163649080.m:1:9: fatal error: module 'CouchbaseLite_Enterprise' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
Update 3:
I filed a YouTrack issue for this. It seems this might have something to do with the dash - in the CocoaPod library name. There was an issue that's been closed that had a fix for this by changing the module name to replace the dash - with an underscore _, but the fix doesn't seem to be working.

Depending on which version of the toolchain you're using, seems as if you're using the wrong syntax to specify the version. Try pod("CouchbaseLite-Enterprise", "~> 2.8.1") instead.

Related

Flutter Plugin project :sign_in_apple not found. Please update settings.gradle

Facing this issue when building the flutter project in Android 31.
ERROR:
Plugin project :sign_in_apple not found. Please update settings.gradle.
FAILURE: Build failed with an exception.
* Where:
Script '/Users/myusername/fluttersdk/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 421
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Cannot invoke method afterEvaluate() on null object
You can just replace this code into the
android>>settings.gradle
include ':app'
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
Check out the steps for adding Apple SignIn to android.
https://pub.dev/packages/sign_in_with_apple
Have run into a similar issue and although the suggestion above works (manually changing the gradle rule to look for the .flutter-plugins file) this should be handled by the default android/settings.gradle file.
The root cause for me turned out to be that the plugin's pubspec.yaml didn't have a
flutter:
plugin:
platforms:
android: # <-- was missing
...
entry. This in return caused it not to show up in android plugins of the .flutter-plugins-dependencies file, which in turn made the flutter gradle rules not pick up the dependency
(The .flutter-plugins file is deprecated in favor of .flutter-plugins-dependencies).

KMM error: This API is internal in ktor and should not be used. It could be removed or changed without notice

After updating Xcode to 13.0, I cannot run my iOS app which is using Kotlin Multiplatform.
Build fails with Command PhaseScriptExecution failed with a nonzero exit code, and it says that the error is:
Task :shared:compileKotlinIos FAILED
e: /Users...path.../KtorClient.kt: (134, 17): This API is internal in ktor and should not be used. It could be removed or changed without notice.
We have also had similar errors after updating to Xcode 13, but it is always something with shared KMM library, JDK etc... This error showed many times:
> Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home/bin/java’' finished with non-zero exit value 1
134 line of KtorClient.kt:
override suspend fun createPassword(email: String, password: String): CreatePasswordResponse {
return client.post {
url {
path("v1", "user", "create_password")
body = LoginRequest(email, password)
}
headers {
/*134.line*/ append(HttpHeaders.ContentType, ContentType.Application.Json)
}
}
}
We have tried deleting XCWorkspace, Podfile.lock, Pods folder, then pod reinstalling, deleting derived data, nothing helped.
We have also tried different versions of Ktor, JDK, nothing helped.
Also this command found on the Internet didnt help(they say you should run it after updating Xcode):
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
This is a known issue of Ktor, related to this fix in Kotlin.
Here's what documentation says:
Note that the StringValuesBuilder class that exposes the append function is incorrectly marked with the InternalAPI annotation. This issue will be fixed in v2.0.0. As a workaround, you can add the #OptIn(InternalAPI::class) annotation to explicitly opt-in to use this API.
You can opt-in your specific line with #OptIn(InternalAPI::class), or add this in your shared module build.gradle.kts to take effect on the whole module:
kotlin {
// ..
sourceSets {
all {
languageSettings.optIn("io.ktor.util.InternalAPI")
}
// ...
}
}

Importing GoogleWebRTC pod fails: module 'GoogleWebRTC' not found

I am currently working on a Kotlin multiplatform and am trying to interface with the GoogleWebRTC pod.
The pod exists, I was able to import it in a separate project (without Kotlin multiplatform). I can see the .framework is created in my build directory, however when doing a gradle sync or building from Xcode, I get the following error:
Exception in thread "main" java.lang.Error: /var/folders/hv/9cx28nxx4gz9hj_m86bp5rx40000gn/T/tmp362966650322311128.m:1:9: fatal error: module 'GoogleWebRTC' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:67)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:13)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:499)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:264)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:72)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)
Execution failed for task ':shared:cinteropGoogleWebRTCIosArm64'.
> Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
AFNetworking seems to work fine, but adding the WebRTC pod seems to break the project.
Am I missing a limitation of Kotlin multiplatform or something?
This is my build.gradle.kts:
cocoapods {
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// You can change the name of the produced framework.
// By default, it is the name of the Gradle project.
frameworkName = "shared"
ios.deploymentTarget = "10.0"
pod("GoogleWebRTC", "~> 1.1")
pod("AFNetworking", "~> 4.0.0")
}
I was able to reproduce this issue but I didn't figure out the reason why.
It seems a there's something wrong with GoogleWebRTC pod and the Kotlin-native/cocoapods integration.
I've opened an issue here.
We have an official help.
It seems that the frameworks name is different from the pod name. So a possible solution could be that:
kotlin {
cocoapods {
[...]
pod("GoogleWebRTC", moduleName = "WebRTC", version = "~> 1.1")
[...]
}
[...]
}
I tried it and it works.

Testing rx throws error on scheduler init

Unit test terminates if I write var scheduler = TestScheduler(initialClock: 0)
my imports
import XCTest
import RxTest
with error message
failed to demangle superclass of TestScheduler from mangled name '7RxSwift20VirtualTimeSchedulerCy0A4Test0fecD9ConverterVG'
pod versions
pod 'RxBlocking', '~> 5'
pod 'RxTest', '~> 5'
This is a bug of the Cocoapods + XCode 10.2 platform.
Statement from XCode 10.2 RC notes about known issues:
Linking against a static Swift library might create a binary with missing
type metadata because the object files that define the metadata inside the
static archive are mistakenly considered unused. (47598583)
This can manifest as a Swift runtime error with a message such as:
“failed to demangle superclass of MyClass from mangled name ‘<mangled name>’”.
Workaround: If you can rebuild the static library, try building it with whole module
optimization enabled.
Otherwise, add -all_load to the linker flags in the client binary to
ensure all object files are linked into it.
This thread and this solution should help you get rid of it.

pod spec lint error: "unexpected '#' in program"

I am creating a podspec file for an open-source project I created, and I am utilizing Apple's UIImage+ImageEffects.h/.m for a blur effect, and inside there, they use the new #import Accelerate; syntax versus #import <Accelerate/Accelerate.h>. When I run pod spec lint SFSCollectionMenu.podspec, I receive the error:
ERROR | [xcodebuild] SFSCollectionMenu/UIImage+ImageEffects.h:96:1: error: unexpected '#' in program
Does the CocoaPods platform not like the new modules syntax? I'm relatively new to CocoaPods so there very well could be something I'm missing. I followed Nils Hayat's blog for creating a simple pod (which fit my scenario perfectly -- nothing outlandish), http://nilsou.com/blog/2013/07/21/how-to-open-source-objective-c-code/, and receive this error in his section about verifying the pod via lint.
Here's relevant lines from podspec file:
s.source_files = 'SFSCollectionMenuController.*{h,m}', 'SFSCircleLayout.*{h,m}', 'SFSMenuCell.*{h,m}', 'UIImage+ImageEffects.*{h,m}'
s.frameworks = 'Accelerate', 'QuartzCore', 'AVFoundation'
Thank you for any help!
I don't think Modules are turned on by default in Xcode, can you test whether adding spec.compiler_flags = "-fmodules" to turn on modules in your generated library fixes this?

Resources