Flutter is not able to install the apk into the real device suddenly
I am working with flutter currently and everything was fine suddenly when I uninstalled the app from the device and rerun flutter run from the terminal it's suddenly not able to install the apk into a real device. It's not even giving any error just getting stopped at the installation process.
What led to this problem
I was working with sqflite and everything was fine. So I had to change the schema and added another table which was failing. Searching on SO answerer suggested to uninstall the app then reinstall it (was accepted answer). So I did that but after every time when I am running flutter run it is not installing the APK.
I am running Mac Os High Sierra 10.13.6 and running flutter doctor is giving everything right as I said it was working fine but not reinstalling after uninstalling.
Solution 1:
Problem
Uninstalling the app from the home page would cause subsequent flutter run
commands to hang at the installing stage.
Running with flutter run -v
showed that it installed successfully but the activity would not run when adb tried to run it.
Error output
The error message was class 3 ${packageName}/${packagName}.MainActivity
not found.
Hacky fix
Changing the android app package name would cause it to work again until I uninstalled it manually from the phone.
Steps that did not work
- Rebooting the phone multiple times
-
flutter clean
didn't work - Restarting Android studio
- Restarting my computer
- Re-enabling USB debugging
- Revoking and authorizing my computer from USB debugging
- Re-enabling developer mode
-
adb shell pm list package ${packageName}
didn't show it in the list so there was nothing to clean through there
Permanent fix
adb uninstall ${packageName}
and it showed 'Success'. Now subsequent flutter runs work perfectly.
Possible cause
It seems uninstalling apps from the home screen does leave some intent or activities in some cache somewhere.
Solution 2:
For me it happens when there are multiple users in the device. When you run the flutter app, it installs the app in all user profiles. So when you just uninstall the app, it only uninstalls the app in the current profile. But the app remains installed in the other profiles. That causes problem when you rerun the app.
To resolve this
- Go to App Info
- Click on the top right menu
- Click on Uninstall for all users
This instructions are only for devices running Stock Android 10.
Solution 3:
I got same problem yesterday and I have tried all the solution.
Finally I got the solution as I have added --no-shrink
in command of building apk.
flutter build apk --no-shrink
Hope it will work.
Thank you.
Solution 4:
Make sure you don't have a work profile on your device. If you do, you need to uninstall all the same apps under your personal profile and work profile.
Solution 5:
Remove all other user profiles from your android phone. Only keep the admin profile. This worked for me!
I also tried re creating the emulator as I sometimes use emulator as well. In case , you are using an emulator create a new one and delete the old one.