Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Add a command to build and run on Android #3239

Merged
merged 8 commits into from
Mar 15, 2021
Merged

Add a command to build and run on Android #3239

merged 8 commits into from
Mar 15, 2021

Conversation

fson
Copy link
Contributor

@fson fson commented Feb 18, 2021

Why

This is going to be the v1 of the emulator flow for Android dev client. The command allows building, installing and launching the dev client app on Android.

How

Launch with expod run --platform android.

TODO:

  • Hide the command from --help

Test Plan

  • Create an app
    npx crna -t with-development-client my-dev-client-app
    cd my-dev-client-app
  • Uncomment this line in android/gradle.properties: # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
  • Build and run it
    expod run:android

@fson fson marked this pull request as draft February 18, 2021 15:48
@fson fson force-pushed the @fson/run-android branch 3 times, most recently from 130debd to 498bf88 Compare February 23, 2021 16:16
@fson fson marked this pull request as ready for review February 24, 2021 16:10
.helpGroup('experimental')
.description('Build a development client and run it in on a device.')
.option('-p --platform <platform>', 'Platform: [android|ios]', /^(android|ios)$/i)
.option('--build-variant [name]', '(Android) build variant', 'release')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm if this is a cross platform command, then we should probably attempt to make the arguments cross-platform too. If that's not feasible, then we should split ios and android build commands up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent was to match the convention used by eas build, where the same command builds iOS and Android apps: eas build --platform ios, eas build --platform android or even eas build --platform all.

It would be possible to do expo run:ios and expo run:android, but this (specifying the platform in the command name) is a pattern we've been trying to avoid in new code.

Cross-plaform arguments: Are you suggesting a new argument that maps to build variant name on Android and build configuration name on iOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to run:android for now. ¯\_(ツ)_/¯

return;
}

const spinner = ora('Building app ').start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this interferes with them, so I'm going to remove the spinner and use Log.log instead.


const spinner = ora('Building app ').start();

const androidProjectPath = await AndroidConfig.Paths.getProjectPathOrThrowAsync(projectRoot);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check to use prebuild here?

  const androidProjectPath = await AndroidConfig.Paths.getProjectPathOrThrowAsync(projectRoot).catch(() => null);
  // If the project doesn't have native code, prebuild it...
  if (!androidProjectPath) {
    await prebuildAsync(projectRoot, {
      install: true,
      platforms: ['android'],
    } as EjectAsyncOptions);
  }

Comment on lines 11 to 13
function getGradleTask(buildVariant: string): string {
return `install${buildVariant.charAt(0).toUpperCase()}${buildVariant.slice(1)}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more types and make it explicitly clear what's going on here. Also iirc, people often use the app: prefix to target just the module? If there's reasoning to do/not do that, could you add it in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split this function, hopefully it's clearer now.

I'm not sure about app:, I found this command in Android docs. If you know more, please let me know.

});

spinner.text = 'Starting the development client...';
await Android.openProjectAsync({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap in a try/catch and fail the spinner

@fson fson force-pushed the @fson/run-android branch from 76052c3 to fe22cf6 Compare February 25, 2021 13:18
@fson fson force-pushed the @fson/run-android branch from 5989a7a to cdc3426 Compare March 10, 2021 16:26
@fson fson requested a review from EvanBacon March 12, 2021 13:52
@fson fson merged commit aebbacf into master Mar 15, 2021
@fson fson deleted the @fson/run-android branch March 15, 2021 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants