Intellij generated Project for Kotlin Multiplatform always show build failed - ios

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.

Related

How debug Kotlin on iOS with Xcode

Currently I am working on one KMM project. It would be really useful to be able to debug the shared code which is in kotlin in xcode project.
I am aware of this solution but I have problem to tell Xcode that *.kt files are source files
to be more specific in the above github link it is written :
You need to tell Xcode that *.kt files are source files, and run an lldb formatter script when debugging starts. Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the setup script.
Unless you're using Xcode 11 (in which case look here for help), the following script will install both debugging and formatting support:
./setup.sh
I do not know where and how I should run the ./setup.sh or if there is another way to do it?
The setup script is included in the github repository: https://github.com/touchlab/xcode-kotlin/blob/main/setup.sh
The above plugin is great if you want to debug on Xcode and I highly recommend it.
Just an FYI, in case you didn't notice, there is also a plugin for debugging shared code on iOS for Android Studio: https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile

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

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.

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

Unity PostProcess Build script fails when running from command line

I am trying to build my project from the command line targeting iOS.
When I build this from the editor, everything works! I have a PostProcess build script that I use.
When I try to build form the command line using the following command:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod BuildScript.BuildIOS -nographics -buildTarget iOS
I am getting an error from my PostProcess build script saying:
Assets/Editor/MyBuildPostprocessor.cs(9,23): error CS0234: The type or namespace name Xcode' does not exist in the namespaceUnityEditor.iOS'. Are you missing an assembly reference?
The line that generates the error is a simple using clause:
using UnityEditor.iOS.Xcode;
So it seems that for some reason, the command line build mechanism does not recognise the UnityEditor.iOS.Xcode assembly, and my PostProcess build script cannot run.
Any ideas?
This is a known case when iOS project is built manually in Unity without errors and fails building on build-server (Unity cloud, Jenkins, TeamCity and others). I think that your case is similar with it. Because if you take a look at the build-server process of building Unity app you'll see that it also uses command line command
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod BuildScript.BuildIOS -nographics -buildTarget iOS
As for build-server issue, the solution is to put all your post-process scripts inside #if UNITY_IOS condition. And it's possible that you've misunderstood the error you get. Unity says that it doesn't understand XCode namespace while trying to include your post-process script inside your build. And of course, Unity can't include XCode namespace because it's available in Unity Editor only.
So try adding #if UNITY_IOS at the very beginning of your post-process source, even before using section and #endif the the very end of the source. In this case Unity won't compile post-process script during building phase, but will call your post-process script after XCode project will be created.
Unfortunately, I couldn't find any information why manual and command line build processes differ.

Using xbuild on iOS application does not generate ipa

We have implemented Continuous Integration with Jenkins to help perform our builds for faster deployment. We have reviewed the documentation provided through the Xamarin website, and have come to an issue. In the walkthrough it describes how to use various plugins to perform the process, we use build scripts to perform our builds because we have some post-actions that we execute after the build, such as submitting the ipa to the TestFlight. The problem is that for iOS it is has been documented that we need to use xbuild instead of mdtool when building from the terminal/command line.
We followed this portion of the guide to construct our xbuild within the build script. It appears that the xbuild command works and creates the project reference dlls and even generates an exe, but does not generate an ipa file even if we set this /p:BuildIpa=true on the xbuild to ensure the ipa generation. We also have provided a location for the ipa to be generated within to ensure we are not missing the file with this /p:IpaPackageDir=$BUILD_PATH. Here is the whole xbuild command that we are currently using, is there something that is incorrect or we are missing?
/Library/Frameworks/Mono.framework/Commands/xbuild $PROJECT_FILE / t:Build /p:BuildIpa=true /p:IpaPackageDir=$BUILD_PATH /p:Configuration=”Release” /p:Platform=”iPhone” /p:OutputPath=$BUILD_PATH
($BUILD_PATH) -- The build path is just “%WORKSPACE%\bin\iPhone\Release\”
I did find this resource as well, which states that xbuild requires the solution file for iOS to build correctly, is that correct?
If this is correct, how do we resolve these errors because I have not been able to find any documentation that explains how to properly define the solution and project files for xbuild deployment, or even how to exclude particular projects during the build:
/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.Forms.UWP/Mobile3.Forms.UWP.csproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/WindowsXaml/v14.0/Microsoft.Windows.UI.Xaml.CSharp.targets, to import. Ignoring.
/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.ServicePro.UWP/Mobile3.ServicePro.UWP.csproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/WindowsXaml/v14.0/Microsoft.Windows.UI.Xaml.CSharp.targets, to import. Ignoring.
Project "/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.sln" (Mobile3.ServicePro.iOS target(s)):
Target ValidateSolutionConfiguration:
/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.sln: error : Invalid solution configuration and platform: "“Release”|“iPhone”".
Task "Error" execution -- FAILED
Done building target "ValidateSolutionConfiguration" in project "/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.sln".-- FAILED
Done building project "/Users/developer/.jenkins/workspace/Mobile3_Branch_3.20/ServicePro/iOS/Mobile3.sln".-- FAILED
Here is the xbuild command we used to build the solution:
/Library/Frameworks/Mono.framework/Commands/xbuild /p:Configuration=”Release” /p:Platform=”iPhone” /p:OutputPath=$BUILD_PATH /p:BuildIpa=true /p:IpaPackageDir=$BUILD_PATH /t:Build $SOLUTION_FILE
We are not concerned with building the UWP projects when building the iOS project because we have a separate build script that generates the appxbundle file correctly.
You can build an "individual project/app" by setting the SolutionDir and building a .csproj, all the referenced projects will be built and an .ipa created, something like:
xbuild
/p:SolutionDir="./src"
/p:OutputPath="$PWD/artifacts/"
/p:IpaPackageDir="$PWD/artifacts/"
/p:Configuration=Release
/p:Platform=iPhone
/target:Build
src/iOS/XamarinForms.iOS.csproj
Note: This assumes your provisioning profiles are setup on this Mac.

Resources