History log of /expo/packages/expo-dev-client/e2e/android/MainApplication.java (Results 1 – 4 of 4)
Revision Date Author Comments
# 036e9444 28-Mar-2023 Evan Bacon <[email protected]>

feat(metro-config): support any entry file in development builds that don't use Expo dev client (#21643)

# Why

- React Native enforces that apps must use `index.js` as the entry file,
this is hi

feat(metro-config): support any entry file in development builds that don't use Expo dev client (#21643)

# Why

- React Native enforces that apps must use `index.js` as the entry file,
this is highly inconvenient and forces us to change the app entry on
`expo prebuild` (cite: [prebuild side
effects](https://github.com/expo/expo/blob/4d2795e/docs/pages/workflow/prebuild.mdx#side-effects)
(`index.js` and `package.json` `scripts`)).
- In #14964 I added support for production Android apps to use any entry
point.
- In #18381 I added the same support to iOS apps in production.
- Development builds using `expo-dev-client` and Expo Go both use a
manifest which support arbitrary entry points.
- This just leaves development builds that don't have Expo code-loading
support (e.g. no manifest/index.html where the script can be changed
dynamically).

# How

- This PR introduces the virtual entry file `.expo/.virtual-metro-entry`
which should never physically exist. When this endpoint is pinged, Expo
CLI will rewrite the the URL to the correct entry point based on the
project configuration. This enables us to fully drop the prebuild
side-effect as no case will require an `index.js` (`index.bundle`) as
the entry file.
- The rewrite means Metro will never support a physical file located at
`.expo/.virtual-metro-entry.js` as this will always be ignored. We could
support forwarding the request if this file exists but we'll probably go
the other way and assert if this file exists to mitigate possible
confusion.
- The name `.expo/.virtual-metro-entry.js` was chosen to be clear and
long enough that users wouldn't try to actually create this file.
- I originally tried using a middleware to perform the redirect but this
wouldn't work with the HMR server which emulates pinging the endpoint
in-memory. Because of this, I went with the metro
`server.rewriteRequestUrl` function.

> This feature is implemented in Expo's Metro configuration, meaning it
should apply to `npx react-native start` (but this is untested and not
officially supported).

## New Setup Instructions for non-prebuild users

Non-prebuild projects will need to modify their `AppDelegate.mm` as
follows:

```diff
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
```

And their `android/app/src/main/java/***/MainApplication.java`:

```diff
@Override
protected String getJSMainModuleName() {
- return "index";
+ return ".expo/.virtual-metro-entry";
}
```

This is of course in addition to the `android/app/build.gradle`:

```groovy
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
```

And iOS production change:

```
shellScript = "if [[ -f \"$PODS_ROOT/../.xcode.env\" ]]; then\n source \"$PODS_ROOT/../.xcode.env\"\nfi\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n# The project root by default is one level up from the ios directory\nexport PROJECT_ROOT=\"$PROJECT_DIR\"/..\n\nif [[ \"$CONFIGURATION\" = *Debug* ]]; then\n export SKIP_BUNDLING=1\nfi\nif [[ -z \"$ENTRY_FILE\" ]]; then\n # Set the entry JS file using the bundler's entry resolution.\n export ENTRY_FILE=\"$(\"$NODE_BINARY\" -e \"require('expo/scripts/resolveAppEntry')\" $PROJECT_ROOT ios relative | tail -n 1)\"\nfi\n\n`\"$NODE_BINARY\" --print \"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\"`\n\n";
```

# Test Plan

### Continuous(-ish)

- Updated the templates to use this new format.

### Quick test

- Start the dev server and ping the entry URL directly:
-
`http://localhost:8081/.expo/.virtual-metro-entry.bundle?platform=web&dev=true&minify=false&modulesOnly=true&runModule=false&shallow=true`
- The redirected URL should show in the `sourceURL` at the end of the
file.

### E2E

- Prebuild, then apply the native changes in a local projects
- Use the following `metro.config.js` (you don't need to use the latest
Expo CLI for this to work):

```js
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("../../expo/packages/@expo/metro-config");
// const { getDefaultConfig } = require('expo/metro-config');

module.exports = getDefaultConfig(__dirname);
```
- `npx expo run:ios` and `npx expo run:android` should point to
`index.bundle`
- Changing the `main` field in the package.json or deleting `index.js`
should continue to work when you reload the app.


# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).

---------

Co-authored-by: Expo Bot <[email protected]>

show more ...


# 052376e8 24-Mar-2022 andy <[email protected]>

[dev-menu][dev-launcher] update dev-menu extensions API (#16558)


# c61511aa 17-Sep-2021 Łukasz Kosmaty <[email protected]>

[dev-client] Fix e2e tests (#14433)

# Why

Fixes failing e2e tests.

# How

- migrated project to use `expo` instead of `expo-modules-core`
- fixed error in `expo-updates-interface`:
```
*

[dev-client] Fix e2e tests (#14433)

# Why

Fixes failing e2e tests.

# How

- migrated project to use `expo` instead of `expo-modules-core`
- fixed error in `expo-updates-interface`:
```
* What went wrong:
Execution failed for task ':expo-updates-interface:mergeLibDexDebugAndroidTest'.
> Could not resolve all files for configuration ':expo-updates-interface:debugAndroidTestRuntimeClasspath'.
> Failed to transform classes.jar (project :expo-modules-core) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=false, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=androidJvm}.
> Execution failed for DexingNoClasspathTransform: /private/var/folders/bs/tw1fkxgx3k34ylc56zcshjgm0000gn/T/3e9d166b08c868189fb9e8ae52bc2c71/node_modules/expo-modules-core/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 24 or above.
```

# Test Plan

- run tests ✅

show more ...


# 8513c0b1 06-Sep-2021 Łukasz Kosmaty <[email protected]>

[dev-client] Add detox e2e tests (#14027)

# Why

Adds detox e2e tests.
Fixes ENG-1611.

Needs:
- [x] https://github.com/expo/expo/pull/14025
- [x] https://github.com/expo/expo/pull/14026
- [

[dev-client] Add detox e2e tests (#14027)

# Why

Adds detox e2e tests.
Fixes ENG-1611.

Needs:
- [x] https://github.com/expo/expo/pull/14025
- [x] https://github.com/expo/expo/pull/14026
- [x] test-runner

# How

Uses a new tool to set up detox tests.

show more ...