Skip to content

Commit 03cebe9

Browse files
committed
Try to preserve the app cache on uninstall.
Context #9259 Due to various reasons `adb` may not be able to preserve the app cache on uninstall. To work around this we have to use the `-k` flag to uninstall the app when using the `cmd package uninstall` call. This will keep the app data and cache on the device. However this might also fail. So in that case we need to completely uninstall the app and then install it again.
1 parent f2eea99 commit 03cebe9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,7 @@ because xbuild doesn't support framework reference assemblies.
29882988
<Target Name="_DeployAppBundle"
29892989
Condition=" '$(AndroidPackageFormat)' == 'aab' "
29902990
DependsOnTargets="_BuildApkSet">
2991+
<!-- Try to uninstall but save the cache -->
29912992
<AndroidAdb
29922993
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' "
29932994
ContinueOnError="True"
@@ -2999,7 +3000,20 @@ because xbuild doesn't support framework reference assemblies.
29993000
>
30003001
<Output TaskParameter="Result" PropertyName="_UninstallResult" />
30013002
</AndroidAdb>
3002-
<AndroidAdb
3003+
<!-- The previous attempt failed. So yry to uninstall but save the cache using cmd package uninstall -k -->
3004+
<AndroidAdb
3005+
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' And '$(_UninstallResult)' == 'false' "
3006+
ContinueOnError="True"
3007+
ToolExe="$(AdbToolExe)"
3008+
ToolPath="$(AdbToolPath)"
3009+
AdbTarget="$(AdbTarget)"
3010+
Command="shell cmd package uninstall -k"
3011+
Arguments="$(_AndroidPackage)"
3012+
>
3013+
<Output TaskParameter="Result" PropertyName="_UninstallResult" />
3014+
</AndroidAdb>
3015+
<!-- adb really can't uninstall this app with the cache intact, we need to completely uninstall it. -->
3016+
<AndroidAdb
30033017
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' And '$(_UninstallResult)' == 'false' "
30043018
ContinueOnError="True"
30053019
ToolExe="$(AdbToolExe)"

0 commit comments

Comments
 (0)