Mobile

Kotlin Multiplatform Mobile for AppCode

Hi everyone,

Today we’re expanding our Kotlin Multiplatform Mobile ecosystem by introducing the Kotlin Multiplatform Mobile (KMM) plugin for AppCode.

By using this plugin you can:

  • Specify the structure of the iOS part of your KMM project in the same way you specify the Android one. We’ve created a special Gradle DSL for describing iOS projects that does not require having .xcodeproj or .xcworkspace.
  • Write Objective-C/Swift and Kotlin code in one IDE. Cross-resolve between Objective-C/Swift and Kotlin works automatically so you can easily jump from the common Kotlin code to its usages in the iOS-specific part. It goes without saying that code completion and code highlighting for Objective-C/Swift are available as well.

The goal is to maintain the project structure in one place and unify the layout of iOS and Android project parts, while preserving all the flexibility that Kotlin Multiplatform Mobile provides.

Pre-requisites

In addition to Xcode, which is required to work with the iOS part, you will need to download the Android SDK. It should be automatically identified by the plugin and set in local.properties:

Android SDK directory

Create a project

In the File | New Project wizard, select the KMM Application template:

New project

AppCode will create a minimal project with iOS and Android “Hello world!” applications. As you can see, the whole iOS application is inside the apple folder. The following minimal DSL is used to describe the project in the corresponding build.gradle.kts:

apple {
    iosApp {
        productName = "mpptest"

        sceneDelegateClass = "SceneDelegate"
        launchStoryboard = "LaunchScreen"
      
        dependencies {
            implementation(project(":shared"))
        }
    }
}

Here we have some predefined properties, such as productName or scenedelegateClass in the iosApp target, that speak for themselves. We can also specify any custom build settings or product info keys in the following way:
productInfo["NSAppTransportSecurity"] = mapOf("NSAllowsArbitraryLoads" to true)
buildSettings["OTHER_LDFLAGS"] = "some_value"

Write the code

The KMM plugin for AppCode provides the same code assistance as the Kotlin/Native plugin did previously. Cross-resolve between Objective-C/Swift and Kotlin works automatically and does not require rebuilding the project:

Code assistance

Build, run, and debug

You can run and debug the Android or iOS part of your application by selecting the corresponding run configuration:

Run configurations

To build the iOS part, AppCode generates a temporary Xcode project and invokes the Xcode build system, so you can be sure that our Gradle project model will work the same as a regular Xcode project does.

If you set a breakpoint inside the shared code or the platform-specific part, the IDE will recognize them and will stop during debugging:

Debug

Test your app

The following test configurations are created automatically:

  • Common Tests – for tests in the commonTest module. We can run them on the local JVM (since unit tests for Android do not have to be run on the simulator) or one of the iOS devices/simulators (since even unit tests on iOS are executed in the simulator).
  • Android Library Tests – for tests in androidTest package (platform-specific tests written in Kotlin for Android).
  • iOS Library Tests – for tests in the iosTest package (platform-specific tests written in Kotlin for iOS).
  • iOS App Tests – for tests in the iosAppTest package, where any iOS tests can be stored.

You can run and debug them (as well as separate tests):

Tests

Supported platforms

Currently, only iOS application and test targets are supported. Android targets are supported in the same way as in Android Studio.

Future plans

We’re working on a solution that will allow you to hook up an existing .xcodeproj or .xcworkspace to the Gradle DSL to make it possible to easily connect existing Xcode projects with the common and Android parts.

We’re also considering integrating some platform-specific IDE functionality. But as a first step, we’re focusing on the language support and project model management to give you a first-class experience for writing your business logic.

That’s it! We hope this new plugin will help you develop your applications easier and faster. You can try it with AppCode EAP builds that are already available for download.

Should you have any feedback for us, don’t hesitate to use the comments section below, submit an issue or feature request to the plugin tracker, or ping AppCode support. Thank you!

Download KMM plugin for AppCode

Discover more