Skip to content

Commit 9333c31

Browse files
committed
feat: only install corresponding abi package when possible
1 parent 6e7eb1e commit 9333c31

File tree

9 files changed

+72
-44
lines changed

9 files changed

+72
-44
lines changed

lib/common/definitions/mobile.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ declare global {
9999
* For iOS simulators - same as the identifier.
100100
*/
101101
imageIdentifier?: string;
102+
103+
/**
104+
* Optional property describing the architecture of the device
105+
* Available for Android only
106+
*/
107+
abis?: string[];
102108
}
103109

104110
interface IDeviceError extends Error, IDeviceIdentifier {}

lib/common/mobile/android/android-device.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ interface IAndroidDeviceDetails {
1313
name: string;
1414
release: string;
1515
brand: string;
16+
'cpu.abi': string;
17+
'cpu.abilist64': string;
18+
'cpu.abilist32': string;
1619
}
1720

1821
interface IAdbDeviceStatusInfo {
@@ -96,6 +99,7 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
9699
identifier: this.identifier,
97100
displayName: details.name,
98101
model: details.model,
102+
abis: details['cpu.abilist64'].split(',').concat(details['cpu.abilist32'].split(',')),
99103
version,
100104
vendor: details.brand,
101105
platform: this.$devicePlatformsConstants.Android,

lib/controllers/build-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class BuildController extends EventEmitter implements IBuildController {
116116
);
117117

118118
if (buildData.copyTo) {
119-
this.$buildArtefactsService.copyLatestAppPackage(
119+
this.$buildArtefactsService.copyAppPackages(
120120
buildData.copyTo,
121121
platformData,
122122
buildData

lib/controllers/deploy-controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ export class DeployController {
2323
},
2424
};
2525
await this.$prepareController.prepare(prepareData);
26-
const packageFilePath = await deviceDescriptor.buildAction();
26+
await deviceDescriptor.buildAction();
2727
await this.$deviceInstallAppService.installOnDevice(
2828
device,
29-
{ ...deviceDescriptor.buildData, buildForDevice: !device.isEmulator },
30-
packageFilePath
29+
{ ...deviceDescriptor.buildData, buildForDevice: !device.isEmulator }
3130
);
3231
};
3332

lib/controllers/run-controller.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ export class RunController extends EventEmitter implements IRunController {
473473
deviceDescriptors: ILiveSyncDeviceDescriptor[]
474474
): Promise<void> {
475475
const rebuiltInformation: IDictionary<{
476-
packageFilePath: string;
477476
platform: string;
478477
isEmulator: boolean;
479478
}> = {};
@@ -509,8 +508,6 @@ export class RunController extends EventEmitter implements IRunController {
509508
);
510509

511510
try {
512-
let packageFilePath: string = null;
513-
514511
// Case where we have three devices attached, a change that requires build is found,
515512
// we'll rebuild the app only for the first device, but we should install new package on all three devices.
516513
if (
@@ -521,24 +518,19 @@ export class RunController extends EventEmitter implements IRunController {
521518
rebuiltInformation[platformData.platformNameLowerCase]
522519
.isEmulator === device.isEmulator)
523520
) {
524-
packageFilePath =
525-
rebuiltInformation[platformData.platformNameLowerCase]
526-
.packageFilePath;
527521
await this.$deviceInstallAppService.installOnDevice(
528522
device,
529-
buildData,
530-
packageFilePath
523+
buildData
531524
);
532525
} else {
533526
const shouldBuild =
534527
prepareResultData.hasNativeChanges ||
535528
(await this.$buildController.shouldBuild(buildData));
536529
if (shouldBuild) {
537-
packageFilePath = await deviceDescriptor.buildAction();
530+
await deviceDescriptor.buildAction();
538531
rebuiltInformation[platformData.platformNameLowerCase] = {
539532
isEmulator: device.isEmulator,
540-
platform: platformData.platformNameLowerCase,
541-
packageFilePath,
533+
platform: platformData.platformNameLowerCase
542534
};
543535
} else {
544536
await this.$analyticsService.trackEventActionInGoogleAnalytics({
@@ -550,8 +542,7 @@ export class RunController extends EventEmitter implements IRunController {
550542

551543
await this.$deviceInstallAppService.installOnDeviceIfNeeded(
552544
device,
553-
buildData,
554-
packageFilePath
545+
buildData
555546
);
556547
}
557548

@@ -710,9 +701,7 @@ export class RunController extends EventEmitter implements IRunController {
710701

711702
await this.$deviceInstallAppService.installOnDevice(
712703
device,
713-
deviceDescriptor.buildData,
714-
rebuiltInformation[platformData.platformNameLowerCase]
715-
.packageFilePath
704+
deviceDescriptor.buildData
716705
);
717706
await platformLiveSyncService.syncAfterInstall(device, watchInfo);
718707
await this.refreshApplication(

lib/definitions/build.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface IBuildArtefactsService {
6161
platformData: IPlatformData,
6262
buildOutputOptions: IBuildOutputOptions
6363
): Promise<string>;
64-
copyLatestAppPackage(
64+
copyAppPackages(
6565
targetPath: string,
6666
platformData: IPlatformData,
6767
buildOutputOptions: IBuildOutputOptions

lib/definitions/run.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ declare global {
2828
interface IDeviceInstallAppService {
2929
installOnDevice(
3030
device: Mobile.IDevice,
31-
buildData: IBuildData,
32-
packageFile?: string
31+
buildData: IBuildData
3332
): Promise<void>;
3433
installOnDeviceIfNeeded(
3534
device: Mobile.IDevice,
36-
buildData: IBuildData,
37-
packageFile?: string
35+
buildData: IBuildData
3836
): Promise<void>;
3937
shouldInstall(
4038
device: Mobile.IDevice,

lib/services/build-artefacts-service.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class BuildArtefactsService implements IBuildArtefactsService {
7575
return [];
7676
}
7777

78-
public copyLatestAppPackage(
78+
public copyAppPackages(
7979
targetPath: string,
8080
platformData: IPlatformData,
8181
buildOutputOptions: IBuildOutputOptions
@@ -85,31 +85,39 @@ export class BuildArtefactsService implements IBuildArtefactsService {
8585
const outputPath =
8686
buildOutputOptions.outputPath ||
8787
platformData.getBuildOutputPath(buildOutputOptions);
88-
const applicationPackage = this.getLatestApplicationPackage(
88+
const applicationPackages = this.getAllAppPackages(
8989
outputPath,
9090
platformData.getValidBuildOutputData(buildOutputOptions)
9191
);
92-
const packageFile = applicationPackage.packageName;
9392

9493
this.$fs.ensureDirectoryExists(path.dirname(targetPath));
9594

95+
let filterFilename: string;
9696
if (
97+
applicationPackages.length > 1 &&
9798
this.$fs.exists(targetPath) &&
98-
this.$fs.getFsStats(targetPath).isDirectory()
99+
!this.$fs.getFsStats(targetPath).isDirectory()
99100
) {
100-
const sourceFileName = path.basename(packageFile);
101+
filterFilename = path.basename(targetPath);
102+
targetPath = path.dirname(targetPath);
101103
this.$logger.trace(
102-
`Specified target path: '${targetPath}' is directory. Same filename will be used: '${sourceFileName}'.`
104+
`Multiple packages were built but only ${filterFilename} will be copied if existing'.`
103105
);
104-
targetPath = path.join(targetPath, sourceFileName);
105106
}
106-
this.$fs.copyFile(packageFile, targetPath);
107-
this.$logger.info(`Copied file '${packageFile}' to '${targetPath}'.`);
107+
applicationPackages.forEach(pack => {
108+
const fileName = path.basename(pack.packageName);
109+
if (!filterFilename || fileName === filterFilename) {
110+
const targetFilePath = path.join(targetPath, path.basename(pack.packageName));
111+
this.$fs.copyFile(pack.packageName, path.join(targetPath, path.basename(pack.packageName)));
112+
this.$logger.info(`Copied file '${pack.packageName}' to '${targetFilePath}'.`);
113+
}
114+
});
108115
}
109116

110117
private getLatestApplicationPackage(
111118
buildOutputPath: string,
112-
validBuildOutputData: IValidBuildOutputData
119+
validBuildOutputData: IValidBuildOutputData,
120+
abis?: string[]
113121
): IApplicationPackage {
114122
let packages = this.getAllAppPackages(
115123
buildOutputPath,

lib/services/device/device-install-app-service.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export class DeviceInstallAppService {
2828

2929
public async installOnDevice(
3030
device: Mobile.IDevice,
31-
buildData: IBuildData,
32-
packageFile?: string
31+
buildData: IBuildData
3332
): Promise<void> {
3433
this.$logger.info(
3534
`Installing on device ${device.deviceInfo.identifier}...`
@@ -49,12 +48,38 @@ export class DeviceInstallAppService {
4948
device,
5049
projectDir: projectData.projectDir,
5150
});
51+
const buildOutputOptions = platformData.getValidBuildOutputData(buildData);
52+
const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData);
53+
const packages = await this.$buildArtefactsService.getAllAppPackages(
54+
outputPath,
55+
buildOutputOptions
56+
);
57+
let packageFile;
58+
if (packages.length === 1) {
59+
// will always be the case on iOS
60+
packageFile = packages[0].packageName;
61+
} else if (device.deviceInfo.abis) {
62+
device.deviceInfo.abis.every(abi=>{
63+
const index = packages.findIndex(p => p.packageName.indexOf(abi) !== -1);
64+
if (index !== -1) {
65+
packageFile = packages[index].packageName;
66+
return false;
67+
}
68+
return true;
69+
})
70+
} else {
71+
//we did not find corresponding abi let's try universal
72+
const index = packages.findIndex(p => p.packageName.indexOf('universal') !== -1);
73+
if (index !== -1) {
74+
packageFile = packages[index].packageName;
75+
}
76+
}
5277

5378
if (!packageFile) {
54-
packageFile = await this.$buildArtefactsService.getLatestAppPackagePath(
55-
platformData,
56-
buildData
79+
this.$logger.error(
80+
`Could not find a package corresponding to the device with identifier '${device.deviceInfo.identifier}'.`
5781
);
82+
return;
5883
}
5984

6085
await platformData.platformProjectService.cleanDeviceTempFolder(
@@ -88,18 +113,17 @@ export class DeviceInstallAppService {
88113
}
89114

90115
this.$logger.info(
91-
`Successfully installed on device with identifier '${device.deviceInfo.identifier}'.`
116+
`Successfully installed on device with identifier '${device.deviceInfo.identifier} using package ${packageFile}'.`
92117
);
93118
}
94119

95120
public async installOnDeviceIfNeeded(
96121
device: Mobile.IDevice,
97-
buildData: IBuildData,
98-
packageFile?: string
122+
buildData: IBuildData
99123
): Promise<void> {
100124
const shouldInstall = await this.shouldInstall(device, buildData);
101125
if (shouldInstall) {
102-
await this.installOnDevice(device, buildData, packageFile);
126+
await this.installOnDevice(device, buildData);
103127
}
104128
}
105129

0 commit comments

Comments
 (0)