Skip to content

Commit fbe4905

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 8c74126 commit fbe4905

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,7 @@ because xbuild doesn't support framework reference assemblies.
29772977
<Target Name="_DeployAppBundle"
29782978
Condition=" '$(AndroidPackageFormat)' == 'aab' "
29792979
DependsOnTargets="_BuildApkSet">
2980+
<!-- Try to uninstall but save the cache -->
29802981
<AndroidAdb
29812982
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' "
29822983
ContinueOnError="True"
@@ -2988,7 +2989,20 @@ because xbuild doesn't support framework reference assemblies.
29882989
>
29892990
<Output TaskParameter="Result" PropertyName="_UninstallResult" />
29902991
</AndroidAdb>
2991-
<AndroidAdb
2992+
<!-- The previous attempt failed. So yry to uninstall but save the cache using cmd package uninstall -k -->
2993+
<AndroidAdb
2994+
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' And '$(_UninstallResult)' == 'false' "
2995+
ContinueOnError="True"
2996+
ToolExe="$(AdbToolExe)"
2997+
ToolPath="$(AdbToolPath)"
2998+
AdbTarget="$(AdbTarget)"
2999+
Command="shell cmd package uninstall -k"
3000+
Arguments="$(_AndroidPackage)"
3001+
>
3002+
<Output TaskParameter="Result" PropertyName="_UninstallResult" />
3003+
</AndroidAdb>
3004+
<!-- adb really can't uninstall this app with the cache intact, we need to completely uninstall it. -->
3005+
<AndroidAdb
29923006
Condition=" '$(EmbedAssembliesIntoApk)' == 'true' And '$(_UninstallResult)' == 'false' "
29933007
ContinueOnError="True"
29943008
ToolExe="$(AdbToolExe)"

0 commit comments

Comments
 (0)