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:
export declare function apiUrlFor(
env: Record<string, string | undefined>,
profile: 'development' | 'preview' | 'production'
): string;
export declare function checkEasConfig(config: unknown): string[];Acceptance criteria
apiUrlForreturnshttps://api.example.comunchanged when given that URL and thepreviewprofile.apiUrlForremoves surrounding whitespace and trailing slashes. For example,https://api.example.com//becomeshttps://api.example.com.- A missing or whitespace-only
EXPO_PUBLIC_API_URLthrows an error containingEXPO_PUBLIC_API_URLfor all three profiles:development,previewandproduction. apiUrlForrejectshttp://api.example.comfor thepreviewandproductionprofiles with an error containinghttps.apiUrlForacceptshttp://192.168.1.20:8080/fordevelopmentand returnshttp://192.168.1.20:8080.apiUrlForrejects a value that is not an absolute URL, such asapi.example.com.apiUrlForrejectshttps://admin:hunter2@api.example.comwith an error containingcredentials.checkEasConfigreturns an empty array for a valid configuration containing the Expo CLI configuration and development, preview and production profiles.checkEasConfigreports at least one problem when givennullor the stringeas.checkEasConfigreports a problem containingpreviewwhen the preview profile is missing.checkEasConfigreports a problem containingapkwhen the preview AndroidbuildTypeisapp-bundle.checkEasConfigreports a problem containinginternalwhen the preview distribution isstore.checkEasConfigreports a problem containingEXPO_PUBLIC_API_URLwhen the preview environment or its API URL is missing.checkEasConfigreports a problem containinghttpswhen the preview API URL useshttp://api.example.com.checkEasConfigreports at least two problems containingsecretwhenEXPO_PUBLIC_JWT_SECRETis added to the production environment andEXPO_PUBLIC_ADMIN_TOKENis added to the preview environment.checkEasConfigreturns an empty array when it reads and validates the actualapp/eas.jsonfile.
Constraints
- Read
EXPO_PUBLIC_API_URLfrom the environment object passed toapiUrlFor. - 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
httpsfor an insecure URL. - Return the cleaned input string, not the normalized
URL.hrefrepresentation. - Treat
checkEasConfiginput asunknown. 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
SECRETandTOKEN. Report detected problems using the wordsecret. Do not flagEXPO_PUBLIC_API_URLas 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:
cd backend
make test W=7B5
cd ../app
npx expo-doctor@latest
eas build -p android --profile previewAll 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.
The reference solution passes every check for this exercise. Try the hints first; reading the answer before you have struggled with the problem teaches much less.
Implementation
Run locally
Write the code in your editor inside zomato-prep, then work through this list.
- All 16 W7B5 Jest tests pass.
- Expo Doctor reports no relevant project configuration issues.
app/eas.jsondefines the development, preview and production profiles.- A preview APK is built and installed on an Android phone.
- The APK is shared with five to ten friends and their feedback is recorded.
Commands
cd backend && make test W=7B5cd app && npx expo-doctor@latestcd app && eas build -p android --profile previewTests
W7 B5 EAS preview build and API URL (16 tests)inapp-tests/lib/eas.test.ts