Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ Builds your app and starts it on a connected Android emulator or device.

#### `--root [string]`

> **DEPRECATED** – root is discovered automatically

Override the root directory for the Android build (which contains the android directory)'.

#### `--variant [string]`
Expand All @@ -315,12 +317,16 @@ Specify your app's build variant.

#### `--appFolder [string]`

> **DEPRECATED** – use "platforms.android.appName" in react-native.config.js

> default: 'app'

Specify a different application folder name for the Android source. If not, we assume is "app".

#### `--appId [string]`

> **DEPRECATED** – use "platforms.android.appName" in react-native.config.js

Specify an `applicationId` to launch after build.

#### `--appIdSuffix [string]`
Expand Down
8 changes: 6 additions & 2 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ An array of iOS script phases to add to the project. Specifying a `path` propert
module.exports = {
dependency: {
platforms: {
ios: {
ios: {
scriptPhases: [
{
name: '[MY DEPENDENCY] My Script',
Expand All @@ -109,7 +109,11 @@ See [`script_phase` options](https://www.rubydoc.info/gems/cocoapods-core/Pod/Po

#### platforms.android.sourceDir

A relative path to a folder with source files. E.g. `custom-android`, or `custom-android/app`. By default, CLI searches for `android` and `android/app` as source dirs.
A relative path to a folder with Android project (Gradle root project), e.g. `./path/to/custom-android`. By default, CLI searches for `./android` as source dir.

#### platforms.android.appName

A name of the app in the Android `sourceDir`, equivalent to Gradle project name. By default it's `app`.

#### platforms.android.manifestPath

Expand Down
25 changes: 7 additions & 18 deletions packages/cli-types/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,20 @@ export interface AndroidProjectConfig {
assetsPath: string;
mainFilePath: string;
packageName: string;
packageFolder: string;
appName: string;
}

export interface AndroidProjectParams {
sourceDir?: string;
manifestPath?: string;
packageName?: string;
packageFolder?: string;
mainFilePath?: string;
stringsPath?: string;
settingsGradlePath?: string;
assetsPath?: string;
buildGradlePath?: string;
}
export type AndroidProjectParams = Partial<AndroidProjectConfig>;

export interface AndroidDependencyConfig {
sourceDir: string;
folder: string;
packageImportPath: string;
packageInstance: string;
appName: string;
manifestPath: string;
packageName: string;
}

export interface AndroidDependencyParams {
packageName?: string;
sourceDir?: string;
manifestPath?: string;
packageImportPath?: string;
packageInstance?: string;
}
export type AndroidDependencyParams = Partial<AndroidDependencyConfig>;
2 changes: 2 additions & 0 deletions packages/cli/src/tools/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const dependencyConfig = t
manifestPath: t.string(),
packageImportPath: t.string(),
packageInstance: t.string(),
appName: t.string(),
})
.default({}),
})
Expand Down Expand Up @@ -126,6 +127,7 @@ export const projectConfig = t
folder: t.string(),
packageImportPath: t.string(),
packageInstance: t.string(),
appName: t.string(),
})
.allow(null),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,169 @@
*/

import runOnAllDevices from '../runOnAllDevices';
import execa from 'execa';

jest.mock('child_process', () => ({
execFileSync: jest.fn(),
spawnSync: jest.fn(),
}));

jest.mock('execa');
jest.mock('../getAdbPath');
jest.mock('../tryLaunchEmulator');
const {execFileSync} = require('child_process');

describe('--appFolder', () => {
const args = {
root: '/root',
appFolder: undefined,
appId: '',
tasks: undefined,
variant: 'debug',
appIdSuffix: '',
mainActivity: 'MainActivity',
deviceId: undefined,
packager: true,
port: 8081,
terminal: 'iTerm2',
jetifier: true,
};
const androidProject = {
manifestPath: '/android/app/src/main/AndroidManifest.xml',
appName: 'app',
packageName: 'com.test',
sourceDir: '/android',
isFlat: false,
folder: '',
stringsPath: '',
buildGradlePath: '',
settingsGradlePath: '',
assetsPath: '',
mainFilePath: '',
packageFolder: '',
};
beforeEach(() => {
jest.clearAllMocks();
});

it('uses task "install[Variant]" as default task', async () => {
// @ts-ignore
await runOnAllDevices({
variant: 'debug',
});
expect(execFileSync.mock.calls[0][1]).toContain('installDebug');
await runOnAllDevices(
{...args, variant: 'debug'},
'./gradlew',
'com.testapp',
'adb',
androidProject,
);
expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'app:installDebug',
);
});

it('uses appName and default variant', async () => {
await runOnAllDevices(
{...args, variant: 'debug'},
'./gradlew',
'com.testapp',
'adb',
{...androidProject, appName: 'someApp'},
);

expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'someApp:installDebug',
);
});

it('uses appName and custom variant', async () => {
await runOnAllDevices(
{...args, variant: 'staging'},
'./gradlew',
'com.testapp',
'adb',
{...androidProject, appName: 'anotherApp'},
);

expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'anotherApp:installStaging',
);
});

it('uses appFolder and default variant', async () => {
// @ts-ignore
await runOnAllDevices({
appFolder: 'someApp',
variant: 'debug',
});
await runOnAllDevices(
{...args, appFolder: 'someApp', variant: 'debug'},
'./gradlew',
'com.testapp',
'adb',
androidProject,
);

expect(execFileSync.mock.calls[0][1]).toContain('someApp:installDebug');
expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'someApp:installDebug',
);
});

it('uses appFolder and custom variant', async () => {
// @ts-ignore
await runOnAllDevices({
appFolder: 'anotherApp',
variant: 'staging',
});
await runOnAllDevices(
{...args, appFolder: 'anotherApp', variant: 'staging'},
'./gradlew',
'com.testapp',
'adb',
androidProject,
);

expect(execFileSync.mock.calls[0][1]).toContain(
expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'anotherApp:installStaging',
);
});

it('uses only task argument', async () => {
// @ts-ignore
await runOnAllDevices({
tasks: ['someTask'],
variant: 'debug',
});
await runOnAllDevices(
{...args, tasks: ['someTask']},
'./gradlew',
'com.testapp',
'adb',
androidProject,
);

expect(execFileSync.mock.calls[0][1]).toContain('someTask');
expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'app:someTask',
);
});

it('uses appName and custom task argument', async () => {
await runOnAllDevices(
{...args, tasks: ['someTask']},
'./gradlew',
'com.testapp',
'adb',
{...androidProject, appName: 'anotherApp'},
);

expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'anotherApp:someTask',
);
});

it('uses appFolder and custom task argument', async () => {
// @ts-ignore
await runOnAllDevices({
appFolder: 'anotherApp',
tasks: ['someTask'],
variant: 'debug',
});

expect(execFileSync.mock.calls[0][1]).toContain('anotherApp:someTask');
await runOnAllDevices(
{...args, appFolder: 'anotherApp', tasks: ['someTask'], variant: 'debug'},
'./gradlew',
'com.testapp',
'adb',
{...androidProject, appName: 'anotherApp'},
);

expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toContain(
'anotherApp:someTask',
);
});

it('uses multiple tasks', async () => {
// @ts-ignore
await runOnAllDevices({
appFolder: 'app',
tasks: ['clean', 'someTask'],
});
await runOnAllDevices(
{...args, tasks: ['clean', 'someTask']},
'./gradlew',
'com.testapp',
'adb',
androidProject,
);

expect(execFileSync.mock.calls[0][1]).toContain(
expect(((execa as unknown) as jest.Mock).mock.calls[0][1]).toEqual([
'app:clean',
// @ts-ignore
'app:someTask',
);
'-PreactNativeDevServerPort=8081',
]);
});
});
Loading