Kotlin Native Xcode Plugin

Overview

Kotlin Native Xcode Support

Plugin to facilitate debugging iOS applications using Kotlin Native in Xcode. Defines Kotlin files as source code, with basic highlighting. Allows you to set breakpoints and includes llvm support to view data in the debug window. Xcode does not officially support custom language definitions, but they also don't explicitly block them.

We're Hiring!

Touchlab is looking for a Mobile Developer, with Android/Kotlin experience, who is eager to dive into Kotlin Multiplatform Mobile (KMM) development. Come join the remote-first team putting KMM in production. More info here.

Installation

There are 2 parts to Kotlin support: 1) debugging support and 2) language color and style formatting.

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

Usage

If properly set up, you should be able to add Kotlin source to Xcode, set up breakpoints, and step through code. To add Kotlin source to Xcode, follow these steps:

  1. Add a New Group to the Xcode project.
  2. Add Files to the newly created group (Kotlin Debug in this instance).
  3. Select the folders in the Kotlin library that are directly relevant to the iOS build, which will usually be commonMain and iosMain. Make sure "Copy items into destination group's folder (if needed)" is unchecked.

When you're done, your Xcode project structure should look something like this:

Sample

The project used as an example above is KaMPKit. Check it out if you want to see a project that already includes Kotlin file references in Xcode. It's an excellent template for Kotlin multiplatform mobile projects.

Sources

Setting up the Plugin has been an amalgam of various source projects, as Xcode "Plugins" are undocumented. The most significant piece, the language color file came from other color files shipped with Xcode. Xcode plugin file from GraphQL

LLDB formatting originally comes from the Kotlin/Native project, source konan_lldb.py, although the way data is grabbed has been heavily modified to better support an interactive debugger.

Possible Future Stuff

Check out the Discussions.

Xcode Updates

Every time Xcode is updated we need the UUID. It needs to be added to Kotlin.ideplugin/Contents/Info.plist. To find the UUID of your version of Xcode, run the following:

defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID

Info from here

Comments
  • xcode-kotlin install  crash (XCode 13.4)

    xcode-kotlin install crash (XCode 13.4)

    I ran brew install xcode-kotlin first and then when I run xcode-kotlin install I get following (crash report hopefully uploaded short while ago) . This is M1 device fwiw. Currently have Xcode 13.4 installed.

    Installing 1.2.0.
    xcode-kotlin has crashed, do you want to upload the crash report to Touchlab? y/n: y
    Uploading crash report.
    Upload successful
    
    opened by joreilly 7
  • Xcode breakpoints indicating that the code is not compiled

    Xcode breakpoints indicating that the code is not compiled

    Hey folks, My team has been using this plugin reliably for a year or so but recently we've found when we set breakpoints in our shared Kotlin code and press run the breakpoints turn to the dotted blue outline state indicating that the code is never executed/compiled - it definitely is getting executed!

    We've tried uninstalling and reinstalling the plugin through the CLI as well as reinstalling with Homebrew but with no luck. We've also reimported the folder references to the shared code in our Xcode project too.

    Interestingly the KaMPKit sample project breakpoints perfectly fine. Any ideas on how to resolve?

    Details

    xcode-kotlin info

    Installed plugin version:	1.2.1
    Bundled plugin version:		1.2.1
    
    Language spec installed: Yes
    LLDB init installed: Yes
    LLDB Xcode init sources main LLDB init: No
    
    Installed Xcode versions:
    ✔	Xcode 14.2 (14C11a)	C91F3560-00E7-4749-8E3F-4D83B1496051	/Applications/Xcode.app
    

    In addition we've also made sure our preprocessor macros for debug is set to: DEBUG=1.

    Expected result

    Breakpoints get triggered when code is executed.

    Current state

    Xcode is indicating that the code is never executed.

    Screenshots

    Screenshot 2022-12-21 at 10 54 40 Screenshot 2022-12-21 at 10 25 55 image Screenshot 2022-12-21 at 11 08 29
    opened by sean-howard 4
  • Add a CLI for installing and updating the plugin

    Add a CLI for installing and updating the plugin

    We should add a CLI that would get installed using Homebrew. There's two ways we could make it work and we should decide which one is better.

    Bundled mode

    In the bundled mode, the plugin files are included with the CLI binary when downloaded by Homebrew. Installing the xcode-plugin formula would automatically put the plugin to the right place. The CLI would then have a single purpose, to update the DVTPlugInCompatibilityUUIDs entry in the plugin's Info.plist file.

    1. Running xcode-plugin repair [xcode path,...] a. Loads UUIDs of all currently installed Xcodes and those provided manually. b. Updates the DVTPlugInCompatibilityUUIDs entry in the installed plugin.
    2. Running xcode-plugin repair --only [xcode path,...] a. Loads UUIDs of only the Xcode paths provided manually. b. Updates the DVTPlugInCompatibilityUUIDs entry in the installed plugin.

    When new changes to the plugin, users would run brew upgrade xcode-kotlin which would perform the same steps as the initial install, updating both the installed plugin and the CLI.

    Independent mode

    In the independent mode, the plugin files live in a separate repository from the CLI. It's up to additional discussion whether the plugin would be installed during the CLI's installation by Homebrew.

    The plugin would then have the following features:

    1. Running xcode-plugin install [version] (xcode-plugin update would do the same) a. Downloads the latest plugin (or the version specified) from GitHub repository. b. Loads UUIDs of currently installed Xcodes and updates the DVTPlugInCompatibilityUUIDs plist entry. c. Copies the modified plugin to the plugins folder
    2. Running xcode-plugin repair [xcode path,...] a. Loads UUIDs of currently installed Xcodes and those provided manually. b. Updates the DVTPlugInCompatibilityUUIDs entry in the installed plugin. c. Fails if the plugin is not installed yet.
    3. Running xcode-plugin repair [xcode path,...] a. Loads UUIDs of only the Xcode paths provided manually. b. Updates the DVTPlugInCompatibilityUUIDs entry in the installed plugin. c. Fails if the plugin is not installed yet.
    enhancement 
    opened by TadeasKriz 4
  • Reference .kt files from a swift package manager pulled repo

    Reference .kt files from a swift package manager pulled repo

    So far the plugin has worked great for me, but I think there is an opportunity to make it even smoother. I have a Kotlin/Native project that generates an xcframework which I then pull in via swift package manager. When I have the Kotlin/Native project locally and registered as a Folder Reference in XCode it works great, but on a new machine where I don't have the original repo synced I cannot easily add breakpoints. Because SPM is based on the git repo it already is syncing all of the .kt files associated with the xcframework. Is there an easy way to make the plugin have access to these files? It would make it much easier for an iOS developer to debug the internals without needing a lot of additional steps.

    The files get synced to /Users/username/Library/Developer/Xcode/DerivedData/Packagename-byqdevosfmstyigxngorlffhsqub/SourcePackages/checkouts

    opened by TrevorStoneEpic 3
  • Try multiple Xcode installs and see if ~/Library/Developer/Xcode is the only folder

    Try multiple Xcode installs and see if ~/Library/Developer/Xcode is the only folder

    Xcode 11 required installing scripts where Xcode was installed. Before and after 11, the files can be installed at ~/Library/Developer/Xcode. I don't know if there is more than one of those folders if there are multiple versions of Xcode installed. If somebody has multiple versions of Xcode (I usually do, but apparently not today), see if there are multiple directories under ~/Library/Developer/.

    opened by kpgalligan 2
  • Not working with Xcode 13.1

    Not working with Xcode 13.1

    I've recently upgraded from Xcode 12.3 to 13.1 and the debugging and syntax formatting is no longer working for me. I've tried re-running the setup script and re-importing my kotlin folders with no success. Has anyone else experienced this?

    opened by MattMur 2
  • Xcode 12.3 support

    Xcode 12.3 support

    It would seems as though the latest update to xcode, 12.3, has broken support for xcode-kotlin. I've tried removing and reinstalling the plugin. When booting xcode, I no longer get the prompt to load the plugin bundle.

    opened by NotBrandon 2
  • Does not work with Xcode 11.2.1

    Does not work with Xcode 11.2.1

    While the DVTPlugInCompatibilityUUID seems to be included in the Plugin Plist, (A74FBA51-FFEA-4409-B976-6FC3225A6F64), Xcode does not seem to approve of that Plugin. Upon Clicking "Load Plugin", Xcode quits, and upon new launches, it will display the dialog to load the plugin, but then immediately quit without the plugin.

    I am using master@aa6bfba

    opened by below 2
  • Pointer sometimes invalid

    Pointer sometimes invalid

    Not sure exactly why, but sometimes the pointer isn't valid. I'm not sure if this is for any data, just arrays, or whatever. The old "check" method would simply skip over invalid pointers. That may be fine, but I'd like to understand what's actually happening.

    python 
    opened by kpgalligan 2
  • Internal testing

    Internal testing

    I'd like the team to try this out. Hopefully we can find any significant bugs before release.

    I think we can merge to main before testing, but I don't want to be out in main too long before we announce.

    cli 
    opened by kpgalligan 1
  • What's new with CLI

    What's new with CLI

    Most users we'll get to the page will be used to the current install. Add a "what's new?" section.

    • Homebrew install and update
    • Local repair on Xcode updates
    • Better diagnostic info if there are issues
    cli 
    opened by kpgalligan 1
  • Can set breakpoints in release build in Xcode, but debug build doesn't see Kotlin files at all

    Can set breakpoints in release build in Xcode, but debug build doesn't see Kotlin files at all

    Hi!

    I've installed plugin from CLI, added iosMain and commonMain as it's suggested in video tutorial

    I observe crashes in my release build in iOS, and for some reason I see kotlin files in stack trace, and I can set breakpoints

    image

    Debug build doesn't allow to set breakpoints at all.

    Output of xcode-kotlin info:

    `Installed plugin version: 1.2.1 Bundled plugin version: 1.2.1

    Language spec installed: Yes LLDB init installed: Yes LLDB Xcode init sources main LLDB init: No

    Installed Xcode versions: ✔ Xcode 13.2.1 (13C90b) 7A3A18B7-4C08-46F0-A96A-AB686D315DF0 /Applications/Xcode.app

    ✔ - plugin is compatible, x - plugin is not compatible Run 'xcode-kotlin sync' to add compatibility for all listed Xcode versions.`

    I've seen how files in filetree look like on the video (with Koltin icon), it's not like that for me:

    image

    I've checked KaMPKitiOS project and it's working fine.

    This project is big, its main contributor has left and I need to make some support fixes for it. Also I'm not very experienced mobile developer but I have been writing some backend/web development for several years.

    Thank you for any help!

    opened by bodritto 0
  • Step into Kotlin from Swift/Objc

    Step into Kotlin from Swift/Objc

    Explore being able to step into Kotlin from calling code (Swift/Objc). I'm pretty sure this isn't possible, but it's something we should explore.

    See Slack for some context: https://kotlinlang.slack.com/archives/C3PQML5NU/p1654805821671169

    opened by kpgalligan 0
  • Kotlin Code Completion in Xcode

    Kotlin Code Completion in Xcode

    Does anyone know if it is possible to extend Xcode's code completion capabilities beyond Swift/Objective-C? I have not done much research on this, but the fact that lldb integrations are possible at least makes the question seem worth asking.

    In any case, if someone here is able to indicate that this is not a complete fool's errand, I'd be happy to run a spike on it and see where it goes!

    • [ ] has-reproduction
    • [x] feature
    • [ ] blocking
    • [ ] good first issue
    opened by JUSTINMKAUFMAN 2
  • Video for installation and usage

    Video for installation and usage

    Should make some installation and usage videos.

    • [ ] Video installing the cli, then installing the plugin. Show the Load Bundle and explain
    • [ ] Video adding source, and debugging. Explain that source built on different machines won't work in the debugger
    • [ ] Video upgrading Xcode
    cli 
    opened by kpgalligan 0
  • Xcode update causes crash

    Xcode update causes crash

    Xcode 13.3.1 (13E500a) crashes on startup M1 Max MBP running macOS 12.3.1.

    Attempted simply rerunning ./setup.sh to reinstall, but it did not solve the issue.

    Solution was to remove the plugin from ~/Library/Developer/Xcode/Plug-ins and the spec from ~/Library/Developer/Xcode/Specifications. Xcode then opened successfully. Ran xcode-kotlin's setup.sh to reinstall. Xcode opens successfully.

    opened by pmodernme 2
Releases(v0.2.2)
Sync Kotlin files with an Xcode project

Kotlin Xcode Sync Note Soon to be deprecated. You can add folder references instead. See here. Import kotlin files into an Xcode project. This is used

null 25 May 20, 2022
The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

Martmists 14 Dec 26, 2022
A plugin for Termux to use native Android GUI components from CLI applications.

Termux:GUI This is a plugin for Termux that enables command line programs to use the native android GUI. In the examples directory you can find demo v

null 342 Dec 23, 2022
Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs

Zipline This library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it possible to do continuous deploymen

Cash App 1.5k Dec 30, 2022
Plugin-shared-preferences - Pluto plugin to manage your Shared Preferences

Pluto Shared Preferences Plugin Pluto Shared Preferences is a Pluto plugin to in

Pluto 1 Feb 14, 2022
An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile. 项目架构主要分为原生系统层、Android/iOS业务SDK层、KMM SDK层、KMM业务逻辑SDK层、iOS sdkfra

libill 4 Nov 20, 2022
A Kotlin Native program to show the time since a date, using Kotlin LibUI

TimeSince A Kotlin Native program to show the time since a date, using Kotlin LibUI Report Bug . Request Feature About The Project TimeSince is a Kotl

Russell Banks 2 May 6, 2022
Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One - Cross Platform Native Apps with Java or Kotlin Codename One is a mobile first cross platform environment for Java and Kotlin developers

Codename One 1.4k Jan 9, 2023
Swift-friendly api generator for Kotlin/Native frameworks

MOKO KSwift KSwift it's gradle plugin for generation Swift-friendly API for Kotlin/Native framework. Kotlin sealed interface/class to Swift enum Kotli

IceRock Development 226 Dec 28, 2022
Native android app made with Kotlin & Compose with example usage of Ktor, SqlDelight.

Delight-Playground ?? Native Android application built with Kotlin and Jetpack Compose. This app also illustrates the usage of advance libraries such

Kasem SM 41 Nov 6, 2022
Utility - The cross-platform native Kotlin command line tool template

Utility The cross-platform native Kotlin command line tool template. Usage Make

null 0 Jan 3, 2022
Kotlin-native webserver for simple image annotations

Kotlin-native webserver for simple image annotations

null 1 Feb 26, 2022
A Kotlin library providing a simple, high-performance way to use off-heap native memory in JVM applications.

native_memory_allocator A library which uses sun.misc.Unsafe to allocate off-heap native memory. Motivation The goal of this project is to provide a s

Target 5 Dec 8, 2022
🎑 Up to date IANA timezone database library for Kotlin (JVM, JS, Native)

?? IANA Timezone Library for Kotlin Multiplatform Up to date IANA timezone database library for Kotlin (JVM, JS, Native) Usage import org.noelware.ian

Noelware 3 Jun 18, 2022
A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

common sense OSS 0 Jan 20, 2022
Display code with syntax highlighting :sparkles: in native way.

CodeView (Android) CodeView helps to show code content with syntax highlighting in native way. Description CodeView contains 3 core parts to implement

Kirill Biakov 827 Dec 22, 2022
Animated tabbar with native control

SSCustomBottomNavigation Getting Started SSCustomBottomNavigation is a customizable bottom bar library with curved animations. The actual features are

Simform Solutions 363 Dec 30, 2022
A React Native library making file access easier for developers as first class citizens, without the tears

React Native File Gateway A React Native library making file access easier for developers as first class citizens, without the tears. ⚠️ NOTE: This li

Jimmy Wei 4 Sep 11, 2021