MobileUI LogoMobileUI
/

Build from Terminal with Gradle

How to build your apps with the Gradle command line


Install Java 8

To build your apps on the command line, you need to install Java 8. There are some problems with compiling Android and RoboVM apps with other Java versions, so please make sure, you are running Java 8 in the build terminal.

We highly recommend the use of SDKMAN to simply switch between Java versions. To check your java version, run the following command in your build terminal:

Check your Java version (with example output)
java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

Building the Android App

A MobileUI app project created by the MobileUI Plugin for Android Studio always contains an Android app module. This module can be built with the default Android Gradle tasks. They are well documented in the official documentation about building your app from the command line. If you plan to build your app for distribution or as part of a continuous integration process, you find all information for building APKs or App Bundles there. For brevity, we will not repeat this information here.

Hint: By default, the Live Server that is required for the Live Preview is automatically disabled for release builds.

Building the iOS App

Building the iOS app on the command line is done by the RoboVM Gradle Plugin. For tasks such as running or debugging your app, we highly recommend using Android Studio with the RoboVM IDEA Plugin, as it is oftentimes better integrated with the latest Xcode.

Building the iOS app on the command line is recommended for scenarios, where you want to create a binary for distribution or are running the build as part of a continuous integration process. We will cover these use cases here.

The command line for building the iOS app from your project root folder is shown below. There are different placeholders within the command. These placeholders are discussed in the following sections

Build the iOS app
./gradlew -i -Probovm.archs=<architectures> -Probovm.iosProvisioningProfile=<name-of-the-profile> \
-Probovm.iosSignIdentity=<id-of-the-identity> createIpa

<architectures>

RoboVM expects you to name one or more architectures to build this app for. If you are building for the App Store, you might consider using the value thumbv7:arm64 to support 32 and 64 bit versions. If you are fine with excluding years old devices, you might go with arm64 only. If the binary should be installed on your simulator, you must also include x86_64 into this list (separated by the colon).

Additionally, you must make sure, that all native frameworks that you are referencing via the robovm.xml file also contain the needed architectures. Frameworks are typically "fat", meaning that they contain several architectures. If you are trying to submit an app to the App Store, you must first strip not required architectures (like x86_64 and i386) from the framework. This can easily be done with the lipo command that comes with Xcode as shown below:

Strip the archs x86_64 and i386 from a framework
lipo -remove x86_64 -output app-ios/libs/SDWebImage.framework/SDWebImage app-ios/libs/SDWebImage.framework/SDWebImage
lipo -remove i386 -output app-ios/libs/SDWebImage.framework/SDWebImage app-ios/libs/SDWebImage.framework/SDWebImage

You can verify that the architectures are removed via the file command:

Checking the contained architectures in a framework
file app-ios/libs/SDWebImage.framework/SDWebImage 
app-ios/libs/SDWebImage.framework/SDWebImage: Mach-O universal binary with 2 architectures: [arm_v7:Mach-O dynamically linked shared library arm_v7] [arm64]
app-ios/libs/SDWebImage.framework/SDWebImage (for architecture armv7):  Mach-O dynamically linked shared library arm_v7
app-ios/libs/SDWebImage.framework/SDWebImage (for architecture arm64):  Mach-O 64-bit dynamically linked shared library arm64

<name-of-the-profile>

For distribution, you need a Provisioning Profile. There are different types of profiles that you can create from Apple's developer portal. Follow this rough guideline:

  • Go to the Apple Developer Protal's Profiles Section and generate a provisioning profile for your specific use case (ad hoc distribution, App Store distribution ...). Please remember the name, you give to the profile during the creation process.
  • Download the profile file (file name with .mobileprovision extension).
  • Double-click the profile file to install it (via Xcode).
  • Add the name of the profile in the above command line for the placeholder <name-of-the-profile>.

<id-of-the-identity>

For different distribution types, you need different signing identities that are allowed to publish your app. You can manage these identities through Xcode and Apple's developer portal. To build the app with RoboVM, you need the ID of the signing identity to use. Proceed as follows:

  • List the locally installed signing identities with their IDs:
List the installed signing identities
security find-identity -v -p codesigning
  1) B5060E5C6FE4B61DAFFAD49D818D9A284C7B1B70 "iPhone Developer: Daniel Thommes (RZJY3P4P92)"
  2) 812C8EDE9037A3779309940B6DCAFCFA03E13690 "iPhone Distribution: NeverNull GmbH (6L7FR2BQJ9)"
     2 valid identities found
  • Replace the placeholder <id-of-the-identity> with the ID of your choice. It's the long Hex-String at the beginning of each line.

Further Reading for Publishers

The topic of building and signing an app for both, Play Store and App Store, is a complicated task. Here are some links, that might help you to understand the specific requirements:

Android

Publish your app: https://developer.android.com/studio/publish

Launch Checklist: https://developer.android.com/distribute/best-practices/launch

iOS

Information about Code Signing: https://developer.apple.com/support/code-signing/

Apple Distribution Overview: https://help.apple.com/xcode/mac/current/#/devac02c5ab8