Building for iOS - gradualgames/ggvm GitHub Wiki

Details on Building for iOS

In order to develop apps for iOS and upload them to the App Store, Apple created some pretty strict guidelines that one must follow in order for the App to be accepted. The process for submitting apps, unsurprisingly, is equally as strict, and sometimes you will receive errors that don't make a lot of sense if you aren't familiar with the process.

Up front let me say that there are two websites that you'll need to have accounts with:

  • developer.apple.com and
  • itunesconnect.apple.com

iTunes Connect is basically a launchpad where you will control many aspects of your App, as well as where you will go after it is uploaded to submit it directly to Apple. You'll need to add a database entry to iTunes Connect for your App, and it will have you create a SKU, and a Bundle ID. When you do this it will also supply you with an Apple ID that identifies your App. You'll need to do this first, as some of this information is required to be used in the following steps.

The second website, the Apple Developer website, is where you will be creating distribution certificates as well as provisioning profiles. I will go into more details below.

The first thing Apple seems to look for when building your app is a Provisioning Profile. This is something one must register through apple.developer.com. There are two types of Provisioning Profiles that Apple offers: Development Provisioning Profiles, and Distribution Provisioning Profiles. In order to build for iOS, at least as far as GGVm is concerned, it is required that one register a Distribution Provisioning Profile. This provisioning profile is linked directly to the App that you registered earlier through iTunes Connect, and basically shows Apple that you have registered the App properly.

The second thing one must have in order to submit an app is an iOS Certificate. Apple offers many different types, depending on if one is developing for iOS or Mac, etc. The only one that you must concern yourself with as far as GGVm is concerned, is an iOS Distribution Certificate. Again, this can be created at apple.developer.com, and shows Apple that you are a legit developer registered through them.

After one has acquired both of these, it's time to add the information into your GGVm code so that when you build your App, Apple will see that you are a certified developer.

Open your ggvm/build.gradle file in your favorite text editor. Down toward the bottom you will see the following code:

project(":ios") {

`apply plugin: "java"`
`apply plugin: "robovm"`
`dependencies {`
    `compile project(":core")`
    `compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"`
    `compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"`
    `compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"`
    `compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"`
`}`

}

Directly below this code, you must add your Distribution Certificate and your Distribution Provisioning Profile information. The full code should look something like this:

project(":ios") { apply plugin: "java" apply plugin: "robovm"

`dependencies {`
    `compile project(":core")`
    `compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"`
    `compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"`
    `compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"`
    `compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"`
`}`

`robovm {`
    `iosSignIdentity = "iPhone Distribution: Kevin Hanley (xxxxxxxxxx)"`
    `iosProvisioningProfile = "Name of Provisioning Profile"`
`}`

}

You can find the actual values for iosSignIdentity by doing the following:

Go to https://developer.apple.com/account/ios/certificate/ and find the Distribution Certificate you created earlier. Click on the download button, and then open the file when it finishes downloading.

After the file has been opened (you may not see your computer actually do anything) you need to open Keychain Access, which is usually located in your Applications/Utilities folder. It should show your exact iPhone Distribution Certificate there with your certificate number.

The value for iosProvisioningProfile is the exact name you made when you created your Distribution Provisioning Profile.

If you haven't done so yet, please edit your ggvm/ios/robovm.properties file to reflect your correct app.id and app.name. These values should correspond with the Bundle ID and SKU that is listed with your App in iTunes Connect.

After all of these values have been updated to reflect your exact information, you should be able to successfully build your IPA file for iOS.

Note: If you haven't ever built for Android, you may get some errors from GGVm complaining that it can't find certain Android build data.

If this is the case, you need to do the following: (if it isn't the case, please skip ahead to the next heading and ignore this)

Open your ggvm/settings.gradle file in your favorite text editor and take out the value for android. Your new file should look like this:

include 'desktop', 'ios', 'core'

You'll also need to delete some unneeded dependencies that it's looking for...

Open your ggvm/desktop/build.gradle file and look for the following code:

`task distPackr(dependsOn: dist, type: JavaExec) {`
`classpath files(packr)`
`main "com.badlogicgames.packr.Packr"`
`args "--platform", platform`
`args "--jdk", jdk`
`args "--executable", gameArchive`
`args "--classpath", "build/libs/" + gameArchive + ".jar"`
`args "--mainclass", "com.gradualgames.ggvm.desktop.DesktopLauncher"`
`args "--vmargs", "Xmx128m"`
`args "--minimizejre", "soft"`
`args "--output", "build/" + game.toLowerCase() + "-" + platform`
`}`

`task distPackrIcon(dependsOn: distPackr, type: Exec) {`
`def gameExe = "build/" + game.toLowerCase() + "-" + platform + "/" + gameArchive + ".exe"`
`def iconFile = "../android/assets/" + game + "/icon/icon.ico"`
`commandLine resourceHacker, "-open", gameExe, "-save", gameExe, "-resource", iconFile, "-action", "add", "-mask", "ICONGROUP,MAINICON,"`
`}`

It can successfully be deleted without issue, as you won't need these dependencies to build specifically for iOS.

Time to build the IPA file for iOS!

After you've sufficiently set up all the files and followed all the previous steps, build your IPA file.

./gradlew ios:createIPA

You should get the command that the build was successful. If you did, congratulations! If you didn't, I apologize, you are getting errors that I didn't come across!

You'll now be able to test your App one of two ways.

Open Xcode, located in your Applications folder (or download it if you haven't yet!) The easiest way to quickly test your app is to go to Windows > Devices. If your Apple device is connected to your computer, you should see it in the list on the left. You should be able to click and drag your IPA file, which is located in ggvm/ios/build/robovm, and drop it in the Installed Apps area. This will load the app on your Apple Device and you should be able to test it.

This is the way to do it when you just want to test yourself, but when you want to bring on friends to help you test your app out, and when you want to submit your app to the App Store, you'll need to do it a similar, but slightly different way.

Using the Application Loader, found in the Xcode dropdown menu, Open Developer Tool > Application Loader, you need to click on the Choose button, located in the bottom right corner. This will allow you to load your IPA file and attempt to upload it to iTunes Connect. Even if you were able to build your IPA file and load it to your iPad with the previous method, uploading it to iTunes Connect looks at the App a little more closely and will probably throw more errors. This is because it's making sure that it complies with all Apple devices, and is a little more strict on what needs to be contained in your App.

I had to add the following code to my ggvm/ios/info.plist.xml file in order to get past these errors:

`<key>MinimumOSVersion</key>`
`<string>8.2.1</string>`

MinimumOSVersion is usually exactly two versions back from the most recent iOS version. This is as far back as Apple officially supports.

`<key>UIRequiresFullScreen</key>`
`<true></true>`

UIRequiresFullScreen basically makes sure that the correct orientation is provided for all iOS devices.

`<string>Icon-App-60x60@2x</string>`
`<string>Icon-App-76x76@1x</string>`
`<string>Icon-App-76x76@2x</string>`

These are various required icon sizes for different Apple Devices. You'll need to add these specific files to the ggvm/ios/data folder. This is the folder where all of your icons are located. There are websites out there where you can submit one icon and it will spit out all the sizes you'll need for all devices.

After these values are added, you should be able to upload to iTunes Connect via Application Loader without issues. If you are having more errors, you are running into issues I didn't come across, so I apologize.

Testing with TestFlight

After your App is uploaded to iTunes Connect, the hard part is over! From here you can test your app together with you and your friends, and even submit it to the App Store for the world to play.

In order to for your friends to test it, you'll have to add their Apple ID to Users and Roles in iTunes Connect. Only certain Roles have the ability to be a tester, so make sure you choose your Roles appropriately. I only allowed my good friends to test, so I just added them as Developers, but your case may be different.

When you add their Apple ID to the Users and Roles area, they should get an email asking them to sign up for iTunes Connect. They won't need to do anything else on the website, but an account is required. After they have signed up, their email address will be available to select in My Apps > App > TestFlight Tab > Internal Testing. Just click the plus sign, and you'll see their email address.

As you make changes to your App, as bugs arise, etc, you'll have to change the version number of your App in order to upload a new version to iTunes Connect via the Application Loader. If you don't, it will not let you upload it, as it will say a duplicate version with that version number already exists. This is handled in the ggvm/ios/robovm.properties file. Just change the app.build value to 1.0.x, or however you would like to notate it, according to your system. After you save this file and rebuild, it should upload without issue.

When you go into iTunes Connect and update the version that your testers should be testing, they will get a push notification and an email alerting them to the new version, and they'll be able to update at this time.

⚠️ **GitHub.com Fallback** ⚠️