Troubleshoot the 'Invalid Package' error on Android APK installation

Posted on 10 Apr 2024
android apk mobile-development tutorial troubleshooting

When you try to manually install an Android APK on your phone, you are typically stuck with an error similar to this:

screenshot showing Android package invalid error

Stack Overflow is filled with posts like this, this and this one but apparently, there seems to be no consensus regarding the cause or even a generally accepted fix for this problem.

The very obvious thing to first do is clean the project and rebuild the APK in Android Studio. Many answers suggest this and if it works for you then well and good. But if rebuilding the APK doesn’t resolve this problem, there are three other solutions you can try based on my practical experience with Android development so far:

  1. If you are signing the final APK with a key, it could be an issue depending on how you sign. Some older android versions may not support the newer V2 signature format, so it’s recommended to sign your APK using both V1 and V2 formats.
  2. I found another solution from this post and it often works in many situations. What values you’ve set for minSdkVersion and targetSdkVersion properties (typically in the app’s build.gradle file) are often the culprit here due to the way android works. Apparently, some newer phones don’t like APKs which support versions lower than M. In my case, I had kept minSdkVersion to 19 (KitKat) and once I changed it to 23 (Marshmallow), this package error mysteriously disappeared! If your user base consists of older android versions, you’ll have to release multiple APKs to cater to that segment in this case.
  3. Apparently, another way this error goes away is by setting the exported attribute for your main Activity in the AndroidManifest.xml like below:
<activity android:name=".LoginActivity"
	android:exported="true"
	>
	<intent-filter>
		<action android:name="android.intent.action.MAIN" />
		<category android:name="android.intent.category.LAUNCHER" />
	</intent-filter>

</activity>

Please let me know whether this resolves your APK package error through comments. Also let me know if you know some other way to fix this error.