Skip to content

Commit 59092f0

Browse files
author
Tsvetan Raikov
committed
Fixed: Livesync on Android is not working after changes in tns-core-modules
1 parent 4f9408a commit 59092f0

11 files changed

+37
-15
lines changed

lib/commands/debug.ts

-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
let applicationReloadAction = (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> => {
1616
return (() => {
1717
let projectData: IProjectData = this.$injector.resolve("projectData");
18-
1918
this.debugService.debugStop().wait();
20-
2119
let applicationId = deviceAppData.appIdentifier;
2220
if (deviceAppData.device.isEmulator && deviceAppData.platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
2321
applicationId = projectData.projectName;
2422
}
2523
deviceAppData.device.applicationManager.stopApplication(applicationId).wait();
26-
2724
this.debugService.debug().wait();
2825
}).future<void>()();
2926
};

lib/definitions/platform.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IPlatformService {
1515
deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
1616
validatePlatformInstalled(platform: string): void;
1717
validatePlatform(platform: string): void;
18+
isPlatformBuilt(platform: string): IFuture<boolean>;
1819

1920
getLatestApplicationPackageForDevice(platformData: IPlatformData): IFuture<IApplicationPackage>;
2021
getLatestApplicationPackageForEmulator(platformData: IPlatformData): IFuture<IApplicationPackage>;

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ interface IPlatformProjectService {
9494
* Ensures there is configuration file (AndroidManifest.xml, Info.plist) in app/App_Resources.
9595
*/
9696
ensureConfigurationFileInAppResources(): IFuture<void>;
97+
isPlatformBuilt(projectRoot: string): IFuture<boolean>;
9798
}
9899

99100
interface IAndroidProjectPropertiesManager {

lib/services/android-project-service.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
4141
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
4242
private $projectTemplatesService: IProjectTemplatesService,
4343
private $xmlValidator: IXmlValidator,
44+
private $config: IConfiguration,
4445
private $npm: INodePackageManager) {
4546
super($fs, $projectData, $projectDataService);
4647
this._androidProjectPropertiesManagers = Object.create(null);
@@ -298,6 +299,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
298299
return this.$fs.exists(path.join(this.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
299300
}
300301

302+
public isPlatformBuilt(projectRoot: string): IFuture<boolean> {
303+
return this.$fs.exists(path.join(projectRoot, "build", "outputs", "apk"));
304+
}
305+
301306
public getFrameworkFilesExtensions(): string[] {
302307
return [".jar", ".dat"];
303308
}
@@ -405,16 +410,18 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
405410
}
406411

407412
public beforePrepareAllPlugins(): IFuture<void> {
408-
let buildOptions = this.getBuildOptions();
409-
buildOptions.unshift("clean");
413+
if (!this.$config.debugLivesync) {
414+
let buildOptions = this.getBuildOptions();
410415

411-
let projectRoot = this.platformData.projectRoot;
412-
let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle";
413-
if (this.$hostInfo.isWindows) {
414-
gradleBin += ".bat";
415-
}
416-
this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
416+
buildOptions.unshift("clean");
417417

418+
let projectRoot = this.platformData.projectRoot;
419+
let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle";
420+
if (this.$hostInfo.isWindows) {
421+
gradleBin += ".bat";
422+
}
423+
this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
424+
}
418425
return Future.fromResult();
419426
}
420427

lib/services/ios-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
357357
return this.$fs.exists(path.join(projectRoot, this.$projectData.projectName, constants.APP_FOLDER_NAME));
358358
}
359359

360+
public isPlatformBuilt(projectRoot: string): IFuture<boolean> {
361+
return this.$fs.exists(path.join(projectRoot, "build"));
362+
}
363+
360364
public deploy(deviceIdentifier: string): IFuture<void> {
361365
return Future.fromResult();
362366
}

lib/services/livesync/android-platform-livesync-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class AndroidPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
1111
protected $injector: IInjector,
1212
protected $projectFilesManager: IProjectFilesManager,
1313
protected $projectFilesProvider: IProjectFilesProvider,
14+
protected $platformService: IPlatformService,
1415
protected $liveSyncProvider: ILiveSyncProvider) {
15-
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider);
16+
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $platformService, $liveSyncProvider);
1617
}
1718

1819
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> {

lib/services/livesync/ios-platform-livesync-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class IOSPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
1111
protected $injector: IInjector,
1212
protected $projectFilesManager: IProjectFilesManager,
1313
protected $projectFilesProvider: IProjectFilesProvider,
14+
protected $platformService: IPlatformService,
1415
protected $liveSyncProvider: ILiveSyncProvider) {
15-
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider);
16+
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $platformService, $liveSyncProvider);
1617
}
1718

1819
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> {

lib/services/livesync/platform-livesync-service-base.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
2424
protected $injector: IInjector,
2525
protected $projectFilesManager: IProjectFilesManager,
2626
protected $projectFilesProvider: IProjectFilesProvider,
27+
protected $platformService: IPlatformService,
2728
protected $liveSyncProvider: ILiveSyncProvider) {
2829
this.liveSyncData = _liveSyncData;
2930
this.fileHashes = Object.create(null);
@@ -78,8 +79,8 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
7879
device.applicationManager.checkForApplicationUpdates().wait();
7980

8081
let appIdentifier = this.liveSyncData.appIdentifier;
81-
if (!device.applicationManager.isApplicationInstalled(appIdentifier).wait()) {
82-
this.$logger.warn(`The application with id "${appIdentifier}" is not installed on device with identifier ${device.deviceInfo.identifier}.`);
82+
if (!device.applicationManager.isApplicationInstalled(appIdentifier).wait() || !this.$platformService.isPlatformBuilt(deviceAppData.platform.toLowerCase()).wait()) {
83+
this.$logger.warn(`Installing application with id "${appIdentifier}" on device with identifier ${device.deviceInfo.identifier}.`);
8384

8485
let packageFilePath = this.$liveSyncProvider.buildForDevice(device).wait();
8586
device.applicationManager.installApplication(packageFilePath).wait();

lib/services/platform-service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ export class PlatformService implements IPlatformService {
618618
return platformData.platformProjectService.isPlatformPrepared(platformData.projectRoot);
619619
}
620620

621+
public isPlatformBuilt(platform: string): IFuture<boolean> {
622+
let platformData = this.$platformsData.getPlatformData(platform);
623+
return platformData.platformProjectService.isPlatformBuilt(platformData.projectRoot);
624+
}
625+
621626
private getApplicationPackages(buildOutputPath: string, validPackageNames: string[]): IFuture<IApplicationPackage[]> {
622627
return (() => {
623628
// Get latest package that is produced from build

test/npm-support.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function createTestInjector(): IInjector {
7878
testInjector.register("mobilePlatformsCapabilities", MobilePlatformsCapabilities);
7979
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
8080
testInjector.register("xmlValidator", XmlValidator);
81+
testInjector.register("config", StaticConfigLib.Configuration);
8182

8283
return testInjector;
8384
}

test/stubs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
324324
isPlatformPrepared(projectRoot: string): IFuture<boolean> {
325325
return Future.fromResult(false);
326326
}
327+
isPlatformBuilt(projectRoot: string): IFuture<boolean> {
328+
return Future.fromResult(false);
329+
}
327330
canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean> {
328331
return Future.fromResult(false);
329332
}

0 commit comments

Comments
 (0)