Android preview APK

You build an Android preview APK from the Expo app using an EAS profile and a validated API URL. The preview profile produces an internally distributed APK with an HTTPS API endpoint.

Ticket

Build an Android preview APK by configuring app/eas.json and implementing API URL resolution and EAS configuration validation in app/lib/eas.ts.

The app leaves your development machine when a tester installs it. Its preview configuration must point to an HTTPS API that their phone can reach. The next exercise seeds the real menu and operating accounts that testers will use with this APK.

The supplied tests call these exported functions:

ts
export declare function apiUrlFor(
  env: Record<string, string | undefined>,
  profile: 'development' | 'preview' | 'production'
): string;

export declare function checkEasConfig(config: unknown): string[];

Acceptance criteria

  • apiUrlFor returns https://api.example.com unchanged when given that URL and the preview profile.
  • apiUrlFor removes surrounding whitespace and trailing slashes. For example, https://api.example.com// becomes https://api.example.com.
  • A missing or whitespace-only EXPO_PUBLIC_API_URL throws an error containing EXPO_PUBLIC_API_URL for all three profiles: development, preview and production.
  • apiUrlFor rejects http://api.example.com for the preview and production profiles with an error containing https.
  • apiUrlFor accepts http://192.168.1.20:8080/ for development and returns http://192.168.1.20:8080.
  • apiUrlFor rejects a value that is not an absolute URL, such as api.example.com.
  • apiUrlFor rejects https://admin:hunter2@api.example.com with an error containing credentials.
  • checkEasConfig returns an empty array for a valid configuration containing the Expo CLI configuration and development, preview and production profiles.
  • checkEasConfig reports at least one problem when given null or the string eas.
  • checkEasConfig reports a problem containing preview when the preview profile is missing.
  • checkEasConfig reports a problem containing apk when the preview Android buildType is app-bundle.
  • checkEasConfig reports a problem containing internal when the preview distribution is store.
  • checkEasConfig reports a problem containing EXPO_PUBLIC_API_URL when the preview environment or its API URL is missing.
  • checkEasConfig reports a problem containing https when the preview API URL uses http://api.example.com.
  • checkEasConfig reports at least two problems containing secret when EXPO_PUBLIC_JWT_SECRET is added to the production environment and EXPO_PUBLIC_ADMIN_TOKEN is added to the preview environment.
  • checkEasConfig returns an empty array when it reads and validates the actual app/eas.json file.

Constraints

  • Read EXPO_PUBLIC_API_URL from the environment object passed to apiUrlFor.
  • Remove surrounding whitespace and trailing slashes before returning the URL.
  • Reject missing or blank URLs with an error containing EXPO_PUBLIC_API_URL.
  • Require an absolute, parseable URL and reject embedded usernames or passwords with an error containing credentials.
  • Allow HTTP for development. Require HTTPS for preview and production, with an error containing https for an insecure URL.
  • Return the cleaned input string, not the normalized URL.href representation.
  • Treat checkEasConfig input as unknown. Report non-object configurations and validate the preview profile, its Android build type, distribution and API URL.
  • Inspect environment variable names across build profiles for secret-looking names, including SECRET and TOKEN. Report detected problems using the word secret. Do not flag EXPO_PUBLIC_API_URL as a secret.
  • Do not modify the provided tests.

Design direction

Keep the URL helper and configuration checker in app/lib/eas.ts. Keep the Expo CLI configuration and build profiles in app/eas.json. The supplied tests import the helper module and read the JSON file directly, so preserve these paths. Any layout that meets the contract passes.

Treat apiUrlFor as the boundary between build configuration and the running app. Use the profile to decide whether HTTP is permitted. Parse the cleaned value to check its URL structure and credentials, but return the cleaned input rather than URL.href.

Keep the three EAS profiles separate. Development needs a development client, internal distribution and an HTTP LAN API URL. Preview needs internal distribution, an APK and an HTTPS API URL. Production needs automatic version increments and an HTTPS API URL. Define the Expo CLI configuration in the same file.

The configuration checker should inspect nested values defensively. Its input can be malformed, so check that each value is an object before reading its properties. Scan environment variable names across profiles rather than checking only preview.

Remember that EXPO_PUBLIC_ variables are included in the public JavaScript bundle. Keep credentials and private tokens out of them. An APK distributed to testers must not depend on a private development address.

How to check your work

Run the supplied tests, check the Expo project configuration, then build the preview APK:

bash
cd backend
make test W=7B5
cd ../app
npx expo-doctor@latest
eas build -p android --profile preview

All 16 EAS-related Jest tests must pass. When a test fails, read the first failing assertion to identify the URL or configuration property that violates the contract before investigating later failures.

After the preview build completes, install the APK on an Android phone and verify that it can reach the configured API. Send the APK to five to ten friends with a one-line explanation of the app and how to install it. Watch them use it without giving instructions, and record where they hesitate or misunderstand the intended flow.

The EAS command uses Expo's cloud build workflow and requires an Expo account. A local Android release build is also an option when your machine has the Android SDK and a compatible Java installation.

Finished Exercise 7.9?

Implementation

Run locally

Write the code in your editor inside zomato-prep, then work through this list.

  1. All 16 W7B5 Jest tests pass.
  2. Expo Doctor reports no relevant project configuration issues.
  3. app/eas.json defines the development, preview and production profiles.
  4. A preview APK is built and installed on an Android phone.
  5. The APK is shared with five to ten friends and their feedback is recorded.

Commands

terminal
cd backend && make test W=7B5
terminal
cd app && npx expo-doctor@latest
terminal
cd app && eas build -p android --profile preview

Tests

  • W7 B5 EAS preview build and API URL (16 tests) in app-tests/lib/eas.test.ts