purfectliterature / expect

Windows script for locally building Expo apps to Android packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expect

Expect is a simple Windows script written in Batch for automating the build of Expo apps to Android packages (APKs or app bundles) locally, without Expo's Turtle build servers, for quick testing.

Expect can easily be extended to support building iOS IPAs (by writing a Shell script). At this stage, Expect is still in early production stage and currently supports building APKs and app bundles for Android on Windows only.

Integrating Expect

All you need to do to integrate Expect is run the following command from a Command Prompt in your Expo project directory:

curl -o setup.bat -s https://raw.githubusercontent.com/purfectliterature/expect/master/setup.bat & setup

If you have previously set up a local Expo build environment on your computer, then all you need to do after invoking the above command is to provide the keystore's credentials in config.txt in .expect. You also need to provide the path to your keystore.jks in config.txt. Note that the path is with respect to your root Expo project directory.

Otherwise, read on.

Setting up a local Expo build environment

The following instructions were adopted from Expo's article. At any time, these instructions may be outdated. If that happens, consult the article and make the necessary adaptations to these instructions.

These steps need only be performed once. So, bear with me here :)

Pre-requisites

  1. expo-cli on your Windows machine (obviously?)
  2. Python 3.x on your Windows machine. You can get the latest distribution here.
  3. Windows Subsystem for Linux set up with bash on your Windows machine.
  4. Node.js set up with Node Version Manager (nvm) on your WSL distro.
  5. turtle-cli installed on your WSL distro. Invoke npm install -g turtle-cli. Don't use Yarn!
  6. expo-cli installed on your WSL distro. Invoke npm install -g expo-cli. You can use Yarn if you want.
  7. Java Development Kit 8 on your WSL distro.
    Note that Android only supports Java 8. Any other Java versions will not work.

Instructions

  1. You first need to create a keystore.
    It is recommended to use Android Studio for this. Open up Android Studio and create an empty project. Go to Build > Generate Signed Bundle > APK. Choose APK, Next, and then click on Create new.... Fill the form and save the keystore.jks.
  2. Then, you need to set up Turtle CLI for building APKs.
    Open Bash on Ubuntu and invoke the following command: turtle setup:android --sdk-version <your Expo SDK version>. You can find your Expo SDK version from package.json. See the version of the "expo" package. For example: turtle setup:android --sdk-version 37.0.3. This will take a while. Ensure that JDK 8 has been configured before invoking this command.

Building with turtle-cli will only work on Unix-based machines. Therefore, you need bash to locally build Expo apps. This step will set up Android SDK and Gradle on your WSL distro for Turtle CLI to build Android packages. Once the process finishes, you are good to go!

Setting Expect up for your project

After invoking the above setup command, you will have an .expect folder. Ideally, this folder should never be commited to your source control. You can add .expect to .gitignore. This behaviour is due to the fact that intrinsically, Expect is just a build tool, and not really a part of your project. Moreover, it contains config.txt that should always be kept secret.

In this folder, you will find a config.txt file with instructions commented in them with hashes (#). Open it up and provide the credentials accordingly (your keystore file name, alias, keystore password, and key password).

Using Expect

Expect should always be used from your Expo project's root directory. From there, open a Command Prompt session and invoke any of the following:

  • .expect\\expect [silent] apk to build APK
  • .expect\\expect [silent] app-bundle to build app bundle

The optional silent parameter will suppress the pre-requisites message and prompt, allowing the build process to start as soon as the above commands are invoked. Note that if you have old exported Expo files in dist, Expo will still ask you if you want to re-export.

The path to output APK or AAB files will be printed in the console by Turtle. By default, it will be located in ~/expo-apps.

Set up a build script with Expect

You can add Expect as a build script to your package manager. Add any of the above commands to scripts in package.json. For example:

...
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "build:apk": ".expect\\expect silent apk",
    "build:aab": ".expect\\expect silent app-bundle"
  },
...

You can choose whatever script name you want. Then, you can simply build by invoking npm run build:apk or yarn build:apk, for example.

How does Expect work?

Since Turtle CLI only works if your Expo app has been published to a server, Expect works by publishing your Expo app to a local server and building your Expo app with turtle-cli from that local server as well. This server is called Experse and I have included the SSL certificates in experse (the cert.pem and key_unencrypted.pem files). If these certificates were to expire, you can generate a new SSL certificate by invoking the following commands:

$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
$ openssl rsa -in key.pem -out key_unencrypted.pem

to get a new pair of .pem files that will work for another year with Experse. Replace the expired .pem files in experse with the new ones.

Turtle CLI only works with HTTPS servers. Therefore, Experse has to have these SSL certificates to work. Note that these certificates are self-signed and will never work for deployment. These certificates are purely for local testing and development only.

About

Windows script for locally building Expo apps to Android packages

License:Apache License 2.0


Languages

Language:Batchfile 73.7%Language:Python 26.3%