Kotlin Multiplatform Mobile unable to run on iOS: Execution failed for task ':shared:compileKotlinIosX64' - ios

I have created fresh project(Hello World) in KMM followed by their official website. In android it works smooth but when I am trying to run in XCode it's giving errors because of which I am unable to build / run the xcode project. I have attached screenshots and logs for my errors. Somehow xcode scheme is not getting generated in the KMM platform that's what I am guessing.
Can anyone please help me understand what am I missing?
Any help would be appriciated.
Following is my dev env:
Xcode 11.4.1
Android 4.1.2
Kotling Plugin version 1.4.30 (stable)
KMM 0.2.0```
XCode Logs:
> Task :shared:compileKotlinIosX64
Downloading native dependencies (LLVM, sysroot etc). This is a one-time action performed only on the first run of the compiler.
Extracting dependency: /Users/fatin/.konan/cache/clang-llvm-apple-8.0.0-darwin-macos.tar.gz into /Users/fatin/.konan/dependencies
e: java.lang.RuntimeException: Cannot extract archive with dependency: /Users/fatin/.konan/cache/clang-llvm-apple-8.0.0-darwin-macos.tar.gz.
> Task :shared:compileKotlinIosX64 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':shared:compileKotlinIosX64'.
> Compilation finished with errors
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
1 actionable task: 1 executed
Command PhaseScriptExecution failed with a nonzero exit code ```
[![enter image description here][3]][3]

I reached out to community for this and finally found the solution. Here is the link to that issue which I raised and solved this problem.
If anyone else is going through this same issue it mostly cause of corrupted kotlin file.
Also try checking your cmd line tools in XCode as per comments.
Hope this helps someone. Cheers.

If the project doesn't run right away even on opening it from Xcode and shows the shared framework is missing, Then try generating the shared framework for iOS platform using terminal. Navigate to the project folder and execute
Command: ./gradlew packForXcode Now the shared framework should have a xcode-frameworks product and you should be able to build and run the project through Xcode.

This could happen if there are two libraries, where one library was compiled against the different version of the other library than the one currently used in the project. Please check that the project configuration is correct and has consistent versions of dependencies.

Related

Flutter: error Xcode: command PhaseScriptExecution failed with a nonzero exit code

I tried to run flutter after updating to the newest stable version
Error output from Xcode build:
↳
** BUILD FAILED **
Xcodes output:
↳
Writing result bundle at path:
/var/folders/56/fc0b38hx7dv7ldxkbs9flh_m0000gn/T/flutter_tools.sDq2W5/flutter_ios_build_temp_dirGNvLvF/temporary_xcresult_bundle
/usr/local/Caskroom/flutter/2.5.2/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/src/interface/local_platform.dart:46:19: Error: Member not
found: 'packageRoot'.
io.Platform.packageRoot; // ignore: deprecated_member_use
^^^^^^^^^^^
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel
Result bundle written to path:
/var/folders/56/fc0b38hx7dv7ldxkbs9flh_m0000gn/T/flutter_tools.sDq2W5/flutter_ios_build_temp_dirGNvLvF/temporary_xcresult_bundle
Could not build the application for the simulator.
Error launching application on iPhone 13 Pro.
I've tried flutter clean and flutter pub get but that isn't the fix. Anyone any idea how to fix this?
As i see you are currently using flutter 2.5.2 which is newest,So Update you flutter SDK by running command
flutter upgrade
Then Upgrade the current package's dependencies to latest versions by running command
flutter pub upgrade
Go to iOS folder of the project run
pod init
and
pod install
I hope this solution solve your problem.
Please up the vote if this answer help you.
I spent way too much time on this issue.
For me the problem was related to the Flutter cache and running the following command resolved the issue:
flutter pub cache repair
The solution made sense to me when I noticed a plugin trying to reference [flutter-sdk-path]/flutter/packages/flutter/lib/screens.dart--which did not exist in my Flutter SDK.
Ref: Update flutter dependencies in /.pub-cache
Guys, sometimes it better to just GO TO SLEEP! It helps a great deal to have fresh eyes looking at a problem.
if you have Podfile in iOS folder
Go to iOS folder of the project
run
flutter clean
and
flutter pub get
and
pod update

Xcode 13 Swift Package Manager Dependency Command CompileSwiftSources failed with a nonzero exit code Error

I'm getting a build error when trying to build my Swift Package Manager package:
Command CompileSwiftSources failed with a nonzero exit code
This always occurs on the dependencies of my package such as KeychainSwift & ReactiveKit (tho I've seen it on other dependencies).
I have tried deleting derived data, restarting Xcode, restarting my computer, going to File > Packages > Reset Package Caches, tried on both Xcode 13.2 beta 2 & Xcode 13.1. Additionally I have verified that my package dependencies are up to date, with no success.
Turns out as I was writing this question, I decided to create a new package to see if I could reproduce it. Just copying the Package.swift file worked fine and didn't reproduce the error.
But after copying my path/source files I got a completely different error about how I can't use macOS storyboards in an iOS target.
On that example project I was able to add the following to the target:
exclude: [
"ViewControllers/macOS"
],
This fixed the build issues on that example package. So I replicated that on the primary package, and it worked perfectly, no build errors.
I have absolutely no idea why Xcode showed a random error message instead of a detailed one that could help me debug further. But hopefully this advice helps someone. Try creating a brand new package, and seeing if that produces a better error message, and ensure that you aren't mixing platform specific code into one target.

compileKotlinIos FAILED - Could not find stdlib

I am trying to compile kotlin multiplatform, which contains iOS target.
I tried different examples over github, but most of them are outdated and don't work, probably because of incompatibility with current tools. Thing, that seems most reasonable is creating Mobile Android/iOS | Gradle or Mobile Shared Library | Gradle project using IntelliJ Idea.
When I create brand new project, I am still getting same error:
> Task :app:compileKotlinIos FAILED
e: Could not find "stdlib" in [~/git/iosandroidtest, ~/.konan/klib, ~/.konan/kotlin-native-macos-1.3.61/klib/common, ~/.konan/kotlin-native-macos-1.3.61/klib/platform/ios_x64].
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileKotlinIos'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
I am using kotlin 1.3.61, xcode 11.3. Any ideas?
Edit:
I pushed empty project (without any changes from me) to github:
https://github.com/hovi/iostest
I think you just ran into a bug with partial archive download.
Per the author there, "I got a snapshot of the .konan directory. It's interesting as it looks like part of the runtime download is there, but some parts are missing. Specifically in this case the common folder in klib, but also the licenses folder.
I was able to repro this locally by killing the build process while the archive is being extracted. For reference, see NativeCompilerDownloader. It looks to see if the folder is there. If not, it'll download and extract. If yes, the build process assumes everything is OK. ... Their local build will certainly be broken from then on until they clean and rebuild ~.konan." I suggest you report your issue there as well. (btw - tried your project in IJ and AS (as well as creating new lib project in IJ), didn't have any issues. Somehow your bad luck with an interrupted download (:))
Link to GitHub issue

Intellij generated Project for Kotlin Multiplatform always show build failed

I am using intellij to create a Kotlin Multiplatform Project for Android and iOS. I have not done any changes to the generated template but when opening the iOS Project in xcode and running it, it shows Build Failed with this logs.
/Users/archie.quinones/Library/Developer/Xcode/DerivedData/iosApp-bwuvtubwlwgrwofszlveznlcosbj/Build/Intermediates.noindex/iosApp.build/Debug-iphonesimulator/app.build/Script-F861D812207FA4320085E80D.sh: line 2: /Users/archie.quinones/IdeaProjects/MppApplication/iosApp/../gradlew: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
Can some guide me how to make this work?
Thank you very much.
There is a small confusion here. AFAIK, there should be a note in your Gradle script, with something like
//Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
So please, open the project directory in Terminal and execute gradle wrapper task manually.
This is a known issue of the Kotlin/MPP wizard, here is the ticket. It is not a problem, as you can produce the wrapper by yourself, but I agree, that it might be unobvious.

mupdf not building in xcode

Not able to build mupdf. I am getting the following error:
Generating cmap and font files
Apple broke Xcode external targets yet again, and I can't be bothered to fix it.
Run the 'make generate' command manually from now on!
If you see an error while running GEN, you've forgotten.
Building libraries for i386.
GEN generated/cmap_cns.h
/bin/sh: ./build/debug-ios-i386/cmapdump: No such file or directory
make: * [generated/cmap_cns.h] Error 127
Do what the error message tells you to do.
Open a terminal, cd to the mupdf directory, and run "make generate".
The same problem.After "make generate", I restarted Xcode, then build successfully.
I was able to generate the MuPDF library without using any make generate or shell script.
I wrote a small step-by-step tutorial on this post.
Cheers

Resources