Skip to content

Commit acb7030

Browse files
Merge pull request #3569 from NativeScript/vladimirov/merge-rel-master
chore: Merge release in master
2 parents 6d88123 + cfca813 commit acb7030

12 files changed

+1037
-1237
lines changed

PublicAPI.md

+25
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const tns = require("nativescript");
4848
* [assetsGenerationService](#assetsgenerationservice)
4949
* [generateIcons](#generateicons)
5050
* [generateSplashScreens](#generatesplashscreens)
51+
* [androidProcessService](#androidprocessservice)
52+
* [getAppProcessId](#getappprocessid)
5153

5254
## Module projectService
5355

@@ -1125,6 +1127,29 @@ tns.assetsGenerationService.generateSplashScreens({ projectDir: "/Users/username
11251127
});
11261128
```
11271129
1130+
## androidProcessService
1131+
The `androidProcessService` exposes methods for getting information about the applications working on Android devices.
1132+
1133+
### getAppProcessId
1134+
The `getAppProcessId` returns the PID of the specified application. If the app is not running on device, the method will return null.
1135+
1136+
* Definition
1137+
```TypeScript
1138+
/**
1139+
* Gets the PID of a running application.
1140+
* @param deviceIdentifier {string} The identifier of the device.
1141+
* @param appIdentifier The identifier of the application.
1142+
* @return {string} Returns the process id matching the application identifier in the device process list.
1143+
*/
1144+
getAppProcessId(deviceIdentifier: string, appIdentifier: string): Promise<string>;
1145+
```
1146+
1147+
* Usage
1148+
```JavaScript
1149+
tns.androidProcessService.getAppProcessId("4df18f307d8a8f1b", "org.nativescript.demoapp")
1150+
.then(pid => console.log(`The PID is ${pid}`))
1151+
.catch(err => console.error(`Error while checking for PID: ${err}`));
1152+
```
11281153
11291154
11301155
## How to add a new method to Public API

docs/man_pages/project/testing/run-ios.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ position: 11
88
Usage | Synopsis
99
---|---
1010
Run on all connected devices | `$ tns run ios [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
11-
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
11+
Run on a selected connected device. Will start simulator with specified `Device Identifier` or `Device Name`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
1212
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release] [--bundle [<value>] [--env.*]]`
13+
Start an emulator with specified device name and sdk | `$ tns run ios [--device <Device Name>] [--sdk <sdk>]`
14+
Start an emulator with specified device identifier and sdk | `$ tns run ios [--device <Device Identifier>] [--sdk <sdk>]`
1315

1416
Runs your project on a connected iOS device or in the iOS Simulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1517

@@ -20,6 +22,7 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur
2022
### Options
2123
* `--device` - Specifies a connected device/simulator to start and run the app.
2224
* `--emulator` - If set, runs the app in all available and configured ios simulators. It will start a simulator if none are already running.
25+
* `--sdk` - Specifies the target simulator's sdk.
2326
* `--justlaunch` - If set, does not print the application output in the console.
2427
* `--clean` - If set, forces rebuilding the native application.
2528
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
@@ -30,6 +33,7 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur
3033

3134
### Attributes
3235
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device ios --available-devices`
36+
* `<Device Name>` is the name of the target simulator as listed by `$ tns device ios --available-devices`
3337
<% } %>
3438
<% if(isHtml) { %>
3539
### Prerequisites

lib/definitions/android-plugin-migrator.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,25 @@ interface IAndroidPluginBuildService {
1313
buildAar(options: IBuildOptions): Promise<boolean>;
1414
migrateIncludeGradle(options: IBuildOptions): boolean;
1515
}
16+
17+
/**
18+
* Describes data required for building plugin for Android.
19+
* The data can be consumed in the buildAndroidPlugin hook.
20+
*/
21+
interface IBuildAndroidPluginData {
22+
/**
23+
* Directory where the plugin will be build.
24+
* Usually this is the `<project dir>/platforms/tempPlugin/<plugin name>` dir.
25+
*/
26+
pluginDir: string;
27+
28+
/**
29+
* The name of the plugin.
30+
*/
31+
pluginName: string;
32+
33+
/**
34+
* Information about tools that will be used to build the plugin, for example compile SDK version, build tools version, etc.
35+
*/
36+
androidToolsInfo: IAndroidToolsInfoData;
37+
}

lib/services/analytics/analytics-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class AnalyticsService extends AnalyticsServiceBase {
5858
gaSettings.customDimensions[GoogleAnalyticsCustomDimensions.client] = this.$options.analyticsClient || (isInteractive() ? AnalyticsClients.Cli : AnalyticsClients.Unknown);
5959

6060
const googleAnalyticsData: IGoogleAnalyticsTrackingInformation = _.merge({ type: TrackingTypes.GoogleAnalyticsData, category: AnalyticsClients.Cli }, gaSettings);
61+
this.$logger.trace("Will send the following information to Google Analytics:", googleAnalyticsData);
6162
return this.sendMessageToBroker(googleAnalyticsData);
6263
}
6364
}
@@ -99,8 +100,6 @@ export class AnalyticsService extends AnalyticsServiceBase {
99100
customDimensions
100101
};
101102

102-
this.$logger.trace("Will send the following information to Google Analytics:", googleAnalyticsEventData);
103-
104103
await this.trackInGoogleAnalytics(googleAnalyticsEventData);
105104
}
106105

lib/services/android-plugin-build-service.ts

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import * as path from "path";
22
import { MANIFEST_FILE_NAME, INCLUDE_GRADLE_NAME, ASSETS_DIR, RESOURCES_DIR } from "../constants";
3-
import { getShortPluginName } from "../common/helpers";
3+
import { getShortPluginName, hook } from "../common/helpers";
44
import { Builder, parseString } from "xml2js";
55
import { ILogger } from "log4js";
66

77
export class AndroidPluginBuildService implements IAndroidPluginBuildService {
88

9-
constructor(private $fs: IFileSystem,
9+
/**
10+
* Required for hooks execution to work.
11+
*/
12+
private get $hooksService(): IHooksService {
13+
return this.$injector.resolve("hooksService");
14+
}
15+
16+
constructor(private $injector: IInjector,
17+
private $fs: IFileSystem,
1018
private $childProcess: IChildProcess,
1119
private $hostInfo: IHostInfo,
1220
private $androidToolsInfo: IAndroidToolsInfo,
@@ -240,30 +248,9 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
240248
}
241249

242250
// finally build the plugin
243-
const gradlew = this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew";
244-
const localArgs = [
245-
gradlew,
246-
"-p",
247-
newPluginDir,
248-
"assembleRelease"
249-
];
250-
251251
this.$androidToolsInfo.validateInfo({ showWarningsAsErrors: true, validateTargetSdk: true });
252-
253252
const androidToolsInfo = this.$androidToolsInfo.getToolsInfo();
254-
const compileSdk = androidToolsInfo.compileSdkVersion;
255-
const buildToolsVersion = androidToolsInfo.buildToolsVersion;
256-
const supportVersion = androidToolsInfo.supportRepositoryVersion;
257-
258-
localArgs.push(`-PcompileSdk=android-${compileSdk}`);
259-
localArgs.push(`-PbuildToolsVersion=${buildToolsVersion}`);
260-
localArgs.push(`-PsupportVersion=${supportVersion}`);
261-
262-
try {
263-
await this.$childProcess.exec(localArgs.join(" "), { cwd: newPluginDir });
264-
} catch (err) {
265-
throw new Error(`Failed to build plugin ${options.pluginName} : \n${err}`);
266-
}
253+
await this.buildPlugin( { pluginDir: newPluginDir, pluginName: options.pluginName, androidToolsInfo });
267254

268255
const finalAarName = `${shortPluginName}-release.aar`;
269256
const pathToBuiltAar = path.join(newPluginDir, "build", "outputs", "aar", finalAarName);
@@ -318,6 +305,26 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
318305
return false;
319306
}
320307

308+
@hook("buildAndroidPlugin")
309+
private async buildPlugin(pluginBuildSettings: IBuildAndroidPluginData): Promise<void> {
310+
const gradlew = this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew";
311+
312+
const localArgs = [
313+
"-p",
314+
pluginBuildSettings.pluginDir,
315+
"assembleRelease",
316+
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
317+
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
318+
`-PsupportVersion=${pluginBuildSettings.androidToolsInfo.supportRepositoryVersion}`
319+
];
320+
321+
try {
322+
await this.$childProcess.spawnFromEvent(gradlew, localArgs, "close", { cwd: pluginBuildSettings.pluginDir });
323+
} catch (err) {
324+
throw new Error(`Failed to build plugin ${pluginBuildSettings.pluginName} : \n${err}`);
325+
}
326+
}
327+
321328
private validateOptions(options: IBuildOptions): void {
322329
if (!options) {
323330
throw new Error("Android plugin cannot be built without passing an 'options' object.");

lib/services/project-data-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class ProjectDataService implements IProjectDataService {
125125

126126
private async getIOSAssetSubGroup(dirPath: string): Promise<IAssetSubGroup> {
127127
const pathToContentJson = path.join(dirPath, AssetConstants.iOSResourcesFileName);
128-
const content = <IAssetSubGroup>this.$fs.readJson(pathToContentJson);
128+
const content = this.$fs.exists(pathToContentJson) && <IAssetSubGroup>this.$fs.readJson(pathToContentJson) || { images: [] };
129129

130130
const imageDefinitions = this.getImageDefinitions().ios;
131131

0 commit comments

Comments
 (0)