Skip to content

Commit dcbbc39

Browse files
authored
feat: run jetifier before run-android (#526)
1 parent 074e742 commit dcbbc39

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

docs/commands.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ Launches the Metro Bundler in a new window using the specified terminal path.
326326
Run custom gradle tasks. If this argument is provided, then `--variant` option is ignored.
327327
Example: `yarn react-native run-android --tasks clean,installDebug`.
328328

329+
#### `--no-jetifier`
330+
331+
> default: false
332+
333+
Do not run [jetifier](https://www.npmjs.com/package/jetifier) – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet.
334+
329335
### `run-ios`
330336

331337
Usage:

packages/platform-android/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"@react-native-community/cli-tools": "^2.4.1",
88
"chalk": "^2.4.2",
9+
"jetifier": "^1.6.2",
910
"logkitty": "^0.5.0",
1011
"slash": "^2.0.0",
1112
"xmldoc": "^0.4.0"

packages/platform-android/src/commands/runAndroid/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
import path from 'path';
1111
import {spawnSync, spawn, execFileSync} from 'child_process';
12+
import chalk from 'chalk';
1213
import fs from 'fs';
13-
1414
import type {ConfigT} from 'types';
15-
1615
import adb from './adb';
1716
import runOnAllDevices from './runOnAllDevices';
1817
import tryRunAdbReverse from './tryRunAdbReverse';
@@ -43,6 +42,7 @@ export type FlagsT = {|
4342
packager: boolean,
4443
port: number,
4544
terminal: string,
45+
jetifier: boolean,
4646
|};
4747

4848
/**
@@ -58,6 +58,19 @@ function runAndroid(argv: Array<string>, config: ConfigT, args: FlagsT) {
5858

5959
warnAboutManuallyLinkedLibs(config);
6060

61+
if (args.jetifier) {
62+
logger.info(
63+
`Running ${chalk.bold(
64+
'jetifier',
65+
)} to migrate libraries to AndroidX. ${chalk.dim(
66+
'You can disable it using "--no-jetifier" flag.',
67+
)}`,
68+
);
69+
// Jetifier is a side-effectful module without a default export. Requiring
70+
// it ad-hoc.
71+
require('jetifier');
72+
}
73+
6174
if (!args.packager) {
6275
return buildAndRun(args);
6376
}
@@ -259,7 +272,7 @@ function startServerInNewWindow(port, terminal, reactNativePath) {
259272
::
260273
:: This source code is licensed under the MIT license found in the
261274
:: LICENSE file in the root directory of this source tree.
262-
275+
263276
@echo off
264277
title Metro Bundler
265278
call .packager.bat
@@ -390,5 +403,11 @@ export default {
390403
description: 'Run custom Gradle tasks. By default it\'s "installDebug"',
391404
parse: (val: string) => val.split(','),
392405
},
406+
{
407+
name: '--no-jetifier',
408+
description:
409+
'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
410+
default: false,
411+
},
393412
],
394413
};

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,6 +5578,11 @@ jest@^24.6.0:
55785578
import-local "^2.0.0"
55795579
jest-cli "^24.7.1"
55805580

5581+
jetifier@^1.6.2:
5582+
version "1.6.2"
5583+
resolved "https://registry.yarnpkg.com/jetifier/-/jetifier-1.6.2.tgz#c1d8b7cc2af1d3a255963dbdaed3d56157e94712"
5584+
integrity sha512-KQKWmj7CNGcOztXwkWoZHoGHJqHBM2hI7YXRHv0tdSz5Gw063CU6z6o8sXaD1+ctTfYQOk+I87NPvPnX/3B3Kw==
5585+
55815586
js-levenshtein@^1.1.3:
55825587
version "1.1.4"
55835588
resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.4.tgz#3a56e3cbf589ca0081eb22cd9ba0b1290a16d26e"

0 commit comments

Comments
 (0)