Video: Building a Codename One Project for iOS
Tags: ios, java, kotlin, mobile
Published: 2021-04-07 11:46:34

This is the third video in my series about [our new online tool, Codename One initializr][1], which allows you to generate a Maven starter project for a native mobile app in one click. The [first video][2] showed how to generate the starter project, and run it in the Codename One simulator. The [second video][3] showed how to build and deploy the project on an Android device. In this video I show how to build and deploy the project on an iOS device.

{% youtube J7UJrtkXHqg %}

## TLDW (Too Long Didn't Watch):

This video starts out with my Codename One project already opened in IntelliJ. See [this post][2] for steps on how to generate this project.

In the video I demonstrate two different approaches for building the iOS app.

1.  **Locally (0:55-2:45)** - Requires a Mac with Xcode Installed.
2.  **Using Build Server (6:45-8:35)** - Can be built on Windows, Linux, or Mac. With no special requirements beyond Maven and the JDK. You just need a free Codename One account.

NOTE: I also show how to generate your iOS certificates and provisioning profiles using the Certificate Wizard (2:45-6:45), as this is required to build apps for iOS.

### Building Locally

The *local build* option generates an Xcode project, which we then open and build using Xcode.

To trigger this build, select "Local Builds" > "Xcode iOS Project":

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-5.51.41-AM.png" alt="Screen Shot 2021-04-06 at 5.51.41 AM" width="448" height="180" class="aligncenter size-full wp-image-583" />

Then press the "Run" button.

It takes the ParparVM compiler a minute or two to do its thing, but when it's done, it opens the generated Xcode project in Xcode.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-5.55.03-AM.png" alt="Screen Shot 2021-04-06 at 5.55.03 AM" width="911" height="517" class="aligncenter size-full wp-image-584" />

Once opened, I press the "Run" button on the Xcode toolbar and wait while it compiles the project. When it is done, it opens the iOS simulator with my app running in it.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-5.58.05-AM.png" alt="Screen Shot 2021-04-06 at 5.58.05 AM" width="317" height="665" class="aligncenter size-full wp-image-585" />

### Building with the Build Server

One of the nice things about Codename One is that it provides a build server with all of the native build tools installed and up-to-date. This simplifies the process of building native apps greatly. You can build your project for iOS, Android, Mac Desktop, Windows Desktop, Windows UWP, and Javascript without requiring any special build tools installed beyond the JDK. Building for any of these targets is as simple as pressing a button, or running a Maven goal.

#### Generating Certificates

Building for iOS requires that you have an Apple developer account. Additionally, Apple requires you to generate certificates and provisioning profiles for your apps. This is by far the most painful part of app development. To help ease the pain, Codename One provides a certificate wizard to help generate these. Before I can submit my first iOS build, I need to walk through the certificate wizard to generate these certificates. The certificate wizard process starts at approx 2:45 in the video, and runs until 6:45.

To access the certificate wizard, I need to open Codename One Settings. I do this by selecting "Tools" > "Codename One Settings" from IntelliJ's configuration menu, then pressing the "Run" button.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.11.27-AM.png" alt="Screen Shot 2021-04-06 at 6.11.27 AM" width="372" height="163" class="aligncenter size-full wp-image-586" />

This will open The Control Center (aka Codename One Settings, aka Codename One Preferences):

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.12.53-AM.png" alt="Screen Shot 2021-04-06 at 6.12.53 AM" width="872" height="460" class="aligncenter size-full wp-image-587" />

Once there, I select "Device Settings" > "iOS" > "Certificate Wizard" from the navigation menu on the left.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.13.55-AM.png" alt="Screen Shot 2021-04-06 at 6.13.55 AM" width="207" height="530" class="aligncenter size-full wp-image-588" />

This displays the login form for the certificate wizard:

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.15.40-AM.png" alt="Screen Shot 2021-04-06 at 6.15.40 AM" width="644" height="330" class="aligncenter size-full wp-image-589" />

IMPORTANT: You need to use your Apple Developer account to login to this form. NOT your Codename One account.

In the video I spliced out some of the waiting time. The login can take a little while, so be patient. Once logged in, it shows me a list of my registered development devices, and I can select which ones I want to be able to deploy this app to for testing and debugging.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.17.06-AM.png" alt="Screen Shot 2021-04-06 at 6.17.06 AM" width="653" height="506" class="aligncenter size-full wp-image-590" />

The above screenshot has all of the rows greyed out. When you log in, you'll see device names and UDIDs listed on this form.

Generally I select all of them. If this is your first time building an iOS app, then you may not have any devices listed yet, and you'll need to click on the "Manage Devices" button and follow the instructions there.

Next, it asks me to confirm that I want to regenerate my certificates, as it has detected that I already have certificates generated in my Apple account. In my case, I say "yes", I'd like to regenerate them, but in most cases, you would select "no", to just use your existing certificates.

TIP: If your certificates were generated by the certificate wizard, then a copy of them has been stored inside the *$HOME/.codenameone/iosCerts* directory, and the wizard will use them automatically. If they weren't generated by the certificate wizard, and you choose *not* to regenerate them, then you may need to specify the location of your certificates in the iOS Settings section.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.25.52-AM.png" alt="Screen Shot 2021-04-06 at 6.25.52 AM" width="648" height="290" class="aligncenter size-full wp-image-592" />

Next, it asks whether we want to generate push certificates. In this case, since this is just a basic *Hello World* app, we don't need push, so I leave these options OFF.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.27.38-AM.png" alt="Screen Shot 2021-04-06 at 6.27.38 AM" width="653" height="282" class="aligncenter size-full wp-image-595" />

After clicking next, it will churn for a bit, and if all goes well, it will show us the message that our certificates were generated and installed successfully.

Just to be sure that my settings are saved. I click on the *hamburger* menu in the upper right, and select "Save".

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.29.40-AM.png" alt="Screen Shot 2021-04-06 at 6.29.40 AM" width="198" height="330" class="aligncenter size-full wp-image-596" />

#### Sending the Build

Now that the certificates are generated, we can send the build. Back in IntelliJ, I select "Build Server" > "iOS Debug Build"

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.32.38-AM.png" alt="Screen Shot 2021-04-06 at 6.32.38 AM" width="384" height="193" class="aligncenter size-full wp-image-597" />

NOTE: If this is your first time building with the build server, you may be prompted for your Codename One username and password.

I then follow the progress of the build on the Codename One website.

When it's finished, I get a set of links to do things like download the .ipa, or install the app on device.

<img src="https://sjhannah.com/blog/wp-content/uploads/2021/04/Screen-Shot-2021-04-06-at-6.34.32-AM.png" alt="Screen Shot 2021-04-06 at 6.34.32 AM" width="378" height="348" class="aligncenter size-full wp-image-598" />

## Get Started

Getting started with your own native app is really easy. Just go to the [Codename One initializr][1], enter your app details, and press "Download".

For more information about Codename One, see [the Codename One website][4].

 [1]: https://start.codenameone.com
 [2]: https://dev.to/shannah/online-tool-to-generate-ios-android-starter-project-k7h
 [3]: https://dev.to/shannah/how-to-deploy-a-codename-one-app-on-android-5h8o
 [4]: https://www.codenameone.com