Skip to content

Commit e00b335

Browse files
committed
Uninstalling before installing to guarantee changes updates
1 parent 1d05824 commit e00b335

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

source/services/Services.ADB.pas

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TADBService = class(TInterfacedObject, IADBServices)
1717
public
1818
procedure ListDevices(const AAdbPath: string; const AStrings: TStrings);
1919
function InstallApk(const AAdbPath, AApkPath, ADevice: string; const AResult: TStrings): boolean;
20+
function UnInstallApk(const AAdbPath, APkgName, ADevice: string; const AResult: TStrings): boolean;
2021
procedure RunApp(const AAdbPath, APkgName, ADevice: string; const AResult: TStrings);
2122

2223
function BuildApk(const AAppBasePath, AAppName: string;
@@ -237,7 +238,20 @@ function TADBService.InstallApk(const AAdbPath, AApkPath, ADevice: string; const
237238
begin
238239
var LStrings := TStringList.Create();
239240
try
240-
ExecCmd(AAdbPath + Format(' -s %s install -r ', [ADevice]) + AApkPath, String.Empty, LStrings);
241+
ExecCmd(AAdbPath + Format(' -s %s install ', [ADevice]) + AApkPath, String.Empty, LStrings);
242+
AResult.AddStrings(LStrings);
243+
Result := (not LStrings.Text.Contains('failure')) and (not LStrings.Text.Contains('failed'));
244+
finally
245+
LStrings.Free();
246+
end;
247+
end;
248+
249+
function TADBService.UnInstallApk(const AAdbPath, APkgName, ADevice: string;
250+
const AResult: TStrings): boolean;
251+
begin
252+
var LStrings := TStringList.Create();
253+
try
254+
ExecCmd(AAdbPath + Format(' -s %s uninstall ', [ADevice]) + APkgName, String.Empty, LStrings);
241255
AResult.AddStrings(LStrings);
242256
Result := (not LStrings.Text.Contains('failure')) and (not LStrings.Text.Contains('failed'));
243257
finally

source/services/Services.App.pas

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ TAppService = class(TInterfacedObject, IAppServices)
3232
const AEnvironmentModel: TEnvironmentModel): boolean;
3333
function InstallApk(const AProjectModel: TProjectModel;
3434
const AEnvironmentModel: TEnvironmentModel; const ADevice: string): boolean;
35+
function UnInstallApk(const AProjectModel: TProjectModel;
36+
const AEnvironmentModel: TEnvironmentModel; const ADevice: string): boolean;
3537
end;
3638

3739
implementation
@@ -157,6 +159,19 @@ function TAppService.InstallApk(const AProjectModel: TProjectModel;
157159
end;
158160
end;
159161

162+
function TAppService.UnInstallApk(const AProjectModel: TProjectModel;
163+
const AEnvironmentModel: TEnvironmentModel; const ADevice: string): boolean;
164+
begin
165+
var LService := TServiceSimpleFactory.CreateAdb();
166+
var LStrings := TStringList.Create();
167+
try
168+
Result := LService.UnInstallApk(AEnvironmentModel.AdbLocation,
169+
AProjectModel.PackageName, ADevice, LStrings);
170+
finally
171+
LStrings.Free();
172+
end;
173+
end;
174+
160175
procedure TAppService.UpdateManifest(const AModel: TProjectModel);
161176
begin
162177
var LManifestPath := GetManifestPath(AModel.ApplicationName);

source/services/Services.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface
2323
const AEnvironmentModel: TEnvironmentModel; const AResult: TStrings): boolean;
2424
function InstallApk(const AAdbPath, AApkPath, ADevice: string;
2525
const AResult: TStrings): boolean;
26+
function UnInstallApk(const AAdbPath, APkgName, ADevice: string;
27+
const AResult: TStrings): boolean;
2628
procedure RunApp(const AAdbPath, APkgName, ADevice: string; const AResult: TStrings);
2729
end;
2830

@@ -34,6 +36,8 @@ interface
3436
const AEnvironmentModel: TEnvironmentModel): boolean;
3537
function InstallApk(const AProjectModel: TProjectModel;
3638
const AEnvironmentModel: TEnvironmentModel; const ADevice: string): boolean;
39+
function UnInstallApk(const AProjectModel: TProjectModel;
40+
const AEnvironmentModel: TEnvironmentModel; const ADevice: string): boolean;
3741
procedure AddScriptFile(const AModel: TProjectModel; const AFileName: string;
3842
const AStream: TStream);
3943
end;

source/views/Form.Main.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ procedure TMainForm.DoDeploy;
144144
//Create and sign the APK file
145145
if BuildApk() then begin
146146
//Install the APK on the device
147+
LAppService.UnInstallApk(FProjectModel, FEnvironmentModel, FDevices.Names[cbDevice.ItemIndex]);
147148
if LAppService.InstallApk(FProjectModel, FEnvironmentModel, FDevices.Names[cbDevice.ItemIndex]) then begin
148149
var LAdbService := TServiceSimpleFactory.CreateAdb();
149150
var LResult := TStringList.Create();

0 commit comments

Comments
 (0)