Run on iOS and Android
ng build --platform turns your app into a real iOS or Android app, with your app's name and icon. You can install it on a virtual phone or on your own phone. Use it to test what your users will get, and to make the files you upload to the app stores.
You never open an Xcode or Android Studio project. The builder generates the native project and builds it for you. You still install Xcode and Android Studio, because their build tools do the compiling.
Install the tools
Each platform needs its own tools. Install the ones for the platforms you build.
iOS: a Mac with Xcode
- Use a Mac. Apple only ships its build tools for macOS, so iOS apps can't be built on Windows or Linux.
- Install Xcode from the Mac App Store. It's a large download.
- Open Xcode once. It asks to install extra components and the iOS platform. Accept both. The iOS platform includes the iOS Simulator, a virtual iPhone that runs on your Mac.
After that, you can close Xcode. The build calls its command-line tools by itself.
Android: Android Studio and a JDK
-
Install Android Studio, on macOS, Windows or Linux. Its setup wizard installs the Android SDK (Android's build tools) and the emulator, which runs virtual Android phones on your computer.
-
Keep the SDK's default location, or set
ANDROID_HOMEto where you put it. The builder looks in:~/Library/Android/sdkon macOS%LOCALAPPDATA%\Android\Sdkon Windows~/Android/Sdkon Linux
-
Install JDK 17 or newer, Java's development kit. Android's build needs it. On macOS, the builder finds an installed JDK by itself. Elsewhere, or to use the JDK that comes with Android Studio, set
JAVA_HOME. For example, on macOS: -
Create a virtual phone. In Android Studio's Device Manager, add a virtual device. You don't have to start it:
--rundoes.
Build the apps
Each build first makes the bundle, as ng build does, then the app around it. You get these files:
The file names come from your app's appName: My App gives MyApp on iOS and my-app on Android.
- The first build is slow. The iOS build downloads a prebuilt copy of the Lynx engine once. The first Android build downloads Android's build system and libraries, which can take several minutes. Later builds take seconds.
- The native project is hidden. The builder generates it in Angular's build cache (
.angular/cache/, whichng newalready git-ignores). It reuses the project until your options change.ng cache cleandeletes it, and the next build generates it again. - When a build fails, the error names the full log file. Read the end of it for the tool's own message.
The generated app shows main.lynx.bundle full screen, and Angular Router handles all navigation inside it. It doesn't open the other bundles of a multi-page app. For those, eject or embed them in your own app.
Run the app
Add --run, and the build installs the app on a virtual phone and opens it:
After a change, run the same command again: the new build replaces the copy that's open.
To choose the phone, name it with --device:
--device names one device, so it goes with --platform ios or --platform android. ng build --platform all --run opens the app on both.
A real iPhone needs a one-time setup first. Run on simulators and phones covers it, and each kind of device.
Next steps
- Run on simulators and phones: each kind of device, and
ng serve --platform, which updates the app as you edit. - Set the app identity: the name, ID, version, icon and splash screen.
- Turn on device features: Bluetooth, NFC, the camera and the rest.
- Permissions: the reasons iOS shows when your app asks.
- Eject the native projects: take over the Xcode and Android Studio projects.
Related
- Publish to the app stores: sign and upload.
- Add native code: your own native modules and elements.
- Build your app: the bundle, budgets and build options.
- Embed in an existing native app
@blotch/angular-lynx-buildAPI and the eject schematic
