diff --git a/docs/commands.md b/docs/commands.md index 5902949d3..e36588124 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -600,6 +600,14 @@ The running metro server port number > default: 8081 +#### `--appId ` + +Specify an `applicationId` to launch after build. If not specified, `package` from AndroidManifest.xml will be used. + +#### `--appIdSuffix ` + +Specify an `applicationIdSuffix` to launch after build. + ### Notes on source map This step is recommended in order for the source map to be generated: diff --git a/packages/cli-hermes/src/profileHermes/downloadProfile.ts b/packages/cli-hermes/src/profileHermes/downloadProfile.ts index c7c5c8c94..d28d9515b 100644 --- a/packages/cli-hermes/src/profileHermes/downloadProfile.ts +++ b/packages/cli-hermes/src/profileHermes/downloadProfile.ts @@ -12,11 +12,11 @@ import { } from '@react-native-community/cli-platform-android'; /** * Get the last modified hermes profile - * @param packageName + * @param packageNameWithSuffix */ -function getLatestFile(packageName: string): string { +function getLatestFile(packageNameWithSuffix: string): string { try { - const file = execSync(`adb shell run-as ${packageName} ls cache/ -tp | grep -v /$ | grep -E '.cpuprofile' | head -1 + const file = execSync(`adb shell run-as ${packageNameWithSuffix} ls cache/ -tp | grep -v /$ | grep -E '.cpuprofile' | head -1 `); return file.toString().trim(); } catch (e) { @@ -37,6 +37,8 @@ function execSyncWithLog(command: string) { * @param sourceMapPath * @param raw * @param generateSourceMap + * @param appId + * @param appIdSuffix */ export async function downloadProfile( ctx: Config, @@ -46,13 +48,20 @@ export async function downloadProfile( raw?: boolean, shouldGenerateSourcemap?: boolean, port?: string, + appId?: string, + appIdSuffix?: string, ) { try { const androidProject = getAndroidProject(ctx); - const packageName = getPackageName(androidProject); + const packageNameWithSuffix = [ + appId || getPackageName(androidProject), + appIdSuffix, + ] + .filter(Boolean) + .join('.'); // If file name is not specified, pull the latest file from device - const file = filename || getLatestFile(packageName); + const file = filename || getLatestFile(packageNameWithSuffix); if (!file) { throw new CLIError( 'There is no file in the cache/ directory. Did you record a profile from the developer menu?', @@ -69,7 +78,7 @@ export async function downloadProfile( // If --raw, pull the hermes profile to dstPath if (raw) { execSyncWithLog( - `adb shell run-as ${packageName} cat cache/${file} > ${dstPath}/${file}`, + `adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${dstPath}/${file}`, ); logger.success(`Successfully pulled the file to ${dstPath}/${file}`); } @@ -80,7 +89,7 @@ export async function downloadProfile( const tempFilePath = path.join(osTmpDir, file); execSyncWithLog( - `adb shell run-as ${packageName} cat cache/${file} > ${tempFilePath}`, + `adb shell run-as ${packageNameWithSuffix} cat cache/${file} > ${tempFilePath}`, ); // If path to source map is not given if (!sourcemapPath) { diff --git a/packages/cli-hermes/src/profileHermes/index.ts b/packages/cli-hermes/src/profileHermes/index.ts index 9fa7727f7..845e95f97 100644 --- a/packages/cli-hermes/src/profileHermes/index.ts +++ b/packages/cli-hermes/src/profileHermes/index.ts @@ -8,6 +8,8 @@ type Options = { sourcemapPath?: string; generateSourcemap?: boolean; port: string; + appId?: string; + appIdSuffix?: string; }; async function profileHermes( @@ -30,6 +32,8 @@ async function profileHermes( options.raw, options.generateSourcemap, options.port, + options.appId, + options.appIdSuffix, ); } catch (err) { throw err as CLIError; @@ -65,6 +69,15 @@ export default { name: '--port ', default: `${process.env.RCT_METRO_PORT || 8081}`, }, + { + name: '--appId ', + description: + 'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.', + }, + { + name: '--appIdSuffix ', + description: 'Specify an applicationIdSuffix to launch after build.', + }, ], examples: [ { diff --git a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts index b1f3ee3df..484f3913b 100644 --- a/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts +++ b/packages/cli-hermes/src/profileHermes/sourcemapUtils.ts @@ -1,11 +1,10 @@ import {Config} from '@react-native-community/cli-types'; -import {logger, CLIError} from '@react-native-community/cli-tools'; +import {logger, CLIError, fetch} from '@react-native-community/cli-tools'; import fs from 'fs'; import path from 'path'; import os from 'os'; import {SourceMap} from 'hermes-profile-transformer'; import ip from 'ip'; -import {fetch} from '@react-native-community/cli-tools'; function getTempFilePath(filename: string) { return path.join(os.tmpdir(), filename);