xref: /expo/tools/src/versioning/android/jarFiles.ts (revision 71ea6032)
1import spawnAsync from '@expo/spawn-async';
2import assert from 'assert';
3import fs from 'fs';
4import path from 'path';
5
6import { EXPOTOOLS_DIR } from '../../Constants';
7
8export async function buildManifestMergerJarAsync(): Promise<string> {
9  const manifestMergerDir = path.join(
10    EXPOTOOLS_DIR,
11    'src',
12    'versioning',
13    'android',
14    'android-manifest-merger'
15  );
16  await spawnAsync('./gradlew', ['build'], {
17    cwd: manifestMergerDir,
18    stdio: 'ignore',
19  });
20  const buildDir = path.join(manifestMergerDir, 'app', 'build');
21  const tarBall = path.join(buildDir, 'distributions', 'app.tar');
22  assert(fs.existsSync(tarBall), `Expected ${tarBall} to exist`);
23  await spawnAsync('tar', ['-xf', tarBall, '-C', buildDir], {
24    cwd: manifestMergerDir,
25    stdio: 'ignore',
26  });
27  const executablePath = path.join(buildDir, 'app', 'bin', 'app');
28  assert(fs.existsSync(executablePath), `Expected ${executablePath} to exist`);
29  return executablePath;
30}
31