So, you have been developing your app for several months now, in an infinite loop of debugging and coding, debugging and coding… when finally, it is time to test a release version of your app. So, you sign and create your release apk (the same as you would when uploading it to the Play Store).
However, when you try to install it, Android says that the app was not installed. Why? It was working fine before when I pressed the debug button in Android Studio. Why, all of a sudden, it’s not working?
Well, the reason is fairly simple. Your debug apk and the release one are not signed by the same key but share the same name package. The debug one is signed with a known key, while the release is signed with your key. So, how do you fix it?
Uninstall the previously installed version
This will remove the already installed debug version, making way for the release.
Uninstall the previously installed version and restart
Unfortunately, some devices store the signing information after the app is uninstalled, and you may need to restart the device to erase that cache.
Is your device pre-Nougat (Android 7)?
In this case, you may need to be careful about how you sign your release version since the APK Signature Scheme v2 was introduced in Android 7.0. It won’t work in devices with versions before that one.
You’ll need to pick both: v1 and v2 to make it work in any version of Android.
Deactivate Play Protect
Sometimes, the good old Play Protect may be misbehaving. So you need to go into the Play Store and disable it (for a bit).
Dude, nothing is working. I’m panicking over here!
Wait, wait. There is another thing you can try. First, you need to change your build variant to release by going into “Select Build Variant” here
The toolbar “Build Variants” will appear, and you must choose release.
Now, at this point, Android Studio will complain if you try to run the app because a release apk needs to be signed. All you need to do is add this signing information for the release build variant by going into “Edit build types”
This windows will show
Pick Modules in the left options, and then click the plus button in the Signing Configs tab, assign a name, like “release”, provide the information in the next image and click apply.
After that, go to Build Variants select release in build types and go down to Signing Config and select the signing config you just created, like this
After it, click OK, wait for it to Sync, and hit the run button (Shift + F10). It will issue a final warning, click OK.
The app will be installed in release mode in your device with your signing information, and from this point forward, you should be able to directly install the apk if you wanted it in that device directly.