Android build version downgrade workaround

When building a version for android that has a smaller bundle version code than the version on your phone you will get an error from android that the version could not be installed (INSTALL_FAILED_VERSION_DOWNGRADE).

I found this discussion on stackoverflow how to prevent/ignore this problem and install the version anyways by setting additional adb install flags like this:

Is it possible to integrate this flag into unity as well? I would really like to get this feature so I don’t have to uninstall the app any time I want to jump back in my version control to see if a problem occurred in that build or since when I got a performance loss.

Do others have that problem as well? @ : Are you already thinking about setting those flags? Are there any drawbacks I might have missed?

1 Like

For better visibility for people with the same problem, here is the error message:
Exception message

UnityException: Unable to install APK!
Installation failed. See the Console for details.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex)
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message)
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuildPointToConsole (System.String title, System.String message)
UnityEditor.Android.PostProcessor.Tasks.PublishPackage.UploadAndStartPlayer (UnityEditor.Android.PostProcessor.PostProcessorContext context, Boolean retryUpload)
UnityEditor.Android.PostProcessor.Tasks.PublishPackage.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:176)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

In Unity 5.4.2 there is still no change to that behavior. This makes me wonder, because I don’t see any drawbacks in setting those flags in the editor deployment.

We are already passing -r.
-d doesn’t work on Android 4.1. I added it but got a regression immediately. So we won’t add it until Android 4.1 support is dropped by Unity.

Oh wow, you’re for sure blowing some dust off this thread!
Anyway, the answer makes a lot of sense and I appreciate that you let me know. It makes me happy to see that you (the unity team) are caring about forum posts. Looking forward to the functionality once 4.1 is dropped :slight_smile:

1 Like

As of Unity 2020.2 the oldest Android version seems to be 4.4. So can we change the adb install invocation now? I’d also like Unity to ignore version codes.

My only reason for sideloading an apk/aab via Unity is to run a development build on a connected test device, so I think it’s safe to overwrite (or add an option to change the invocation via ProjectSettings).

Also, it’s especially annoying because I also want to test the Google Play internal testing or closed testing releases. So I often just download and start them to make sure they are ok for testers, but when I then continue developing in Unity, my local versionCode won’t be correct, because Google Play builds are handled via the build server pipeline, but local builds are not. I think this is a common setup.

I see -d option already passed to adb install command line in the code. Are you still experiencing the issue?

In 2020.2.1f1 the error still appears when trying to overwrite a newer version. Can I see the invocation that happens somewhere in Unity or the log? Or maybe even modify/hack this locally?

EDIT: See post below. My issue was actually the different signing keys. A different issue with different solutions.

We use -d in Unity 2020.2. Your issue is probably not about the version downgrade, but about a different signature. If you have installed an app from the Google Play signed with a publishing key, then you won’t be able to overwrite it with the local build signed with a development key or an upload key. The app must be first uninstalled in this case.
You can see the exact error which caused the install to fail in Unity editor’s console window (and in the editor’s log). There you should also see the invocation command with its arguments.
Currently there is no option in Unity editor to uninstall the app from the device and there are no plans to add it. If you often run into this issue, you could automate the app removal with a script, by running “adb uninstall ”.

2 Likes