Update Android Native app to Flutter without uninstalling [INSTALL_FAILED_UPDATE_INCOMPATIBLE] - android

I have an app on Google Play Store. I rewrote that app on Flutter but not published yet. I don't want users to lose their data on update. To solve this I want to write a conversion system but I need to be able to reach old database when Flutter app launches.
Android system doesn't allow two different app with same package name installed. When I try to install Flutter app on a device that has Native app, Visual Studio debugger gives [INSTALL_FAILED_UPDATE_INCOMPATIBLE] error. It uninstalls Native app and installs Flutter app so I won't be able to reach Native app's sqlite database.
Also the reason why I use the Google Play version is I lost my old project's latest update files. There is no fraud no worries :)
What I tried:
Make Flutter app's package name same as Native app's.
Sign debug version with Native app's keystore file.
Give Flutter app a higher version than Native app.
After steps I did above, first build stuck at Running Gradle task 'assembleDebug'.... Output stays like this (I waited several times, maximum for 30 mins):
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
If I clean project, it builds in 30 seconds but uninstalls Native app with this output:
Running "flutter pub get" in projectname_2...
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Error: ADB exited with exit code 1
Performing Streamed Install
adb: failed to install /Users/xxxxxx/projectname/build/app/outputs/flutter-apk/app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package ataberkw.projectname signatures do not match previously installed version; ignoring!]
Uninstalling old version...
W/FlutterActivityAndFragmentDelegate(11073): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
Connecting to VM Service at ws://127.0.0.1:58745/lUE5l2_VlN4=/ws

I realized that Google Play has it's own signature system additional to your keystore signing. Things may not exactly what I said but consequently apks Google Play and apks signed with your keystore doesn't have the same certificate. After this realization I came up with a solution.
Install the app from Google Play Store.
adb adb shell pm path ataberkw.packagename to get path of base.apk.
./adb pull base-apk-path destination-path to get base apk
Rename base.apk to base.zip and open it.
Delete META-INF folder inside base.zip and rename it to base.apk back. Now you have unsigned apk.
I used this automatic apk signer but you can use manual ways too.
Reproduce the data at Native app and now you can install signed (use same jks file) Flutter app without need of uninstall.

Have you checked your app's applicationId's? If they are the same, that might make OS think that you are installing the same app again.
In Flutter, your applicationId is located in android\app\build.gradle file. You can address here for documentation.

Related

apk failed on android 12

Last week I passed from a Android 10 phone to Android 12.
I had some apks decompiled/recompiled with apktool and autosigned with jarsigner, and in Android 10 I could installed them, but in Android 12 it just shows me the apk is invalid when I try to install them at the phone.
If I just decompile one and compile again, and then signed it gives me the same error. I also tryed to install it via adb install with the same result.
I also get the same doing it with Apk Edit app in the phone, so I asume with Android 12 google restringed the apk installations in the phone, but not for all of them, because I installed some apk that I had for more than 5 years and they were installed fine.
Could it be some attribute in the manifest?
I will appreciatte some light to the topic.
Regards
You problem is jarsigner. Jarsigner creates an Android APK signature v1 which is no longer accepted on modern devices.
If you want to resign an app you have to use apksigner from Android SDK as it is capable of creating an APK signature v2 and v3. It is included in build tools for each platform, for example build tools for platform API 30.
Apksigner is a Java program so it doesn't mater if you download Linux, MacOS or Windows version:
Download build-tools_r30.0.1-windows.zip
Extract from the downloaded ZIP file android-11/lib/apksigner.jar
Execute java -jar apksigner to execute Apksigner.
For a full list of commands how to generate the necessary signing keys and sign an APK please refer to this answer: https://android.stackexchange.com/a/226152/2241
Since play store started to accept AAB upload, APKs are started to build for spesific ABIs and OS versions by play store. Your problem may be caused from this situation.
For example; you can't install an apk that build for armeabi-v7a to your arm64-v8a based phone.
if this is the problem you can download appropriate apk variation from apkmirror.

React Native app crashes after installed on real device

Just rebuilt React Native app as the previous version failed in building on Android emulator. The React Native is upgraded from 0.66 to 0.67 and a few other modules, such as React Native gesture handler, were upgraded as well.
The app works fine on Android 2021.1.1 Patch 2 emulator. However after downloading the release package from the distribution server, the app installed on Android 10 device quits as soon as launching without giving any error.
What is the problem with the release package? Here is the build steps:
./gradlew bundleRelease
bundletool build-apks to build mypackage.apks with signature.
unzip it into mypackage.apk
Connecting android device to dev Mac using USB cable, the app was launched successfully on the real device. And the app can be launched successfully late as well. I notice that the size of the app is 77MB which is about twice as big as the app installed from the universal apk.
If you need to check apk on real device, follow this build steps:
Release APK Generation.
Place your terminal directory to Android using:
cd android
Then run the following command:
For Windows:
gradlew assembleRelease
For Linux and Mac OSX:
./gradlew assembleRelease
As a result, the APK creation process is done. You can find the generated APK at android/app/build/outputs/apk/app-release.apk. This is the actual app, which you can send to your phone or upload to the Google Play Store. Congratulations, you’ve just generated a React Native Release Build APK for Android.
There are frequent errors that show up in this process sometimes, which is typical to a React Native app, given React Native is continuously evolving. We are laying out here the most frequent React Native build errors that we ran into, to save you time and headaches.

How can I sign Android application with AOSP certificate

The context of my issue is the following:
I build AOSP for our hardware device on Linux
Together with the system, I build an APK as a system application
Everything works fine in this setup when I flesh it together with system image
However, I would like to have this application build separated from the AOSP build and be able to build it standalone and install from Windows.
On windows, I am trying to build it with Gradle
And the problem arises when I try to push the build to the device the following way:
adb install -r my_app.apk
adb: failed to install my_app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package <...> signatures do not match the previously installed version; ignoring!]
Obviously the error means that I am missing a platform signature in the application, but where to take it from the AOSP build and how to sign it with Gradle build is not so clear.
Also here I found an advice to uninstall the system app first before installing. Unfortunately, for my case it does not help, the error is still the same even I uninstall it first.
I already spend quite some time on this, searching in the Android make-files for the signing script, but it seems to be not that straight forward there.
Any help would be highly appreciated...
Create a keystore from platform.x509.pem and platform.pk8 files located in build/target/product/security. Then use that with gradle.
See this answer for how to do the conversion: https://stackoverflow.com/a/22214826/3801327
Note: Don't use the default keys included with AOSP, everyone has those, and would be able to make their app a system app in your platform. Generate your own keys.

How to debug an app upgrade in Android Studio on a USB connected device

I have the production release of my Google Play Store app on my phone and have an updated version of the app in Android Studio. I would like to test the upgrade process, but have run into a versioning problem, then a logging problem.
To get a "clean" install, I can go into my phone's settings Backup & reset > Automatic restore, turn that off, then de-install the app, and install it from the Play Store. Alternatively, I could download the production APK and install it from the adb command line (details below). The result is my device should be the same as a regular production user.
Not directly germane to the question, but to understand my motivation for watching the upgrade process is that the app has an SQLite database and I extend SQLiteOpenHelper, so onUpgrade() is called, and some database schema work is being done.
Update Incompatible
If I click the button to deploy the app, then select my connected device, it wants to uninstall before proceeding:
Installation failed with message Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE
Obviously I could uninstall, but that would not test the upgrade process!
Generating Signed APK
I built a "release" APK, using Generate Signed APK..., which is the same process I use when generating a release for uploading to the Play Store. This gets around the versioning problem, but causes a logging visibility problem. The release configuration used in the past and now looks like this:
Installing APK to the device from Command Line
"C:\Program Files (x86)\HTC\HTC Sync Manager\HTC Sync\adb" install -r app-release.apk
The above did upgrade without uninstalling. The process I used was to open Terminal within Android Studio, change directory to where the generated APK was stored, then type the above command.
Logging / Debugging Problems
The adb command line triggered the upgrade process, but it did not start feeding the Logcat window immediately with debug information. I could connect to Logcat for all processes, but I could not get debug information for just my process, and did not have access to debugging tools.
Question
How can I start with a device that's running a signed production release then cause an updated version, contained in Android Studio, to run, without uninstalling, and with the ability to see the debugging output during the upgrade process? Or how can I modify a signed production release such that it allows an new version to update and allow debugging?
Because you're starting with an APK that is Debuggable=false, your work-around that includes building an update to the app using the same process as your production release process and getting a Logcat with all processes is probably the best you can do.
Rebuilding from Previous Source Control Version
One option would be to pull the specific version of the app out of your source control system and build it with Debuggable=true, and use that generated APK as your starting point instead of using the APK from the Play Store.
For the Future
Instead of making only one APK release version and uploading that to Play Store, make two versions. One version would be signed and uploaded as usual. And with the exact same source code, make another APK that has Debuggable=true. Rename each file with the version number. Then, later, if you ever want to try an upgrade from any version to any version, you can do that, and still have debugging capability.

Installation failed with message INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package signatures do not match the previously installed version

I want to run my application in phone but I get following message:
Installation failed with message:
INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package signatures do not match
the previously installed version; ignoring!.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.
WARNING: Uninstalling will remove the application data!
Do you want to uninstall the existing application?
In my phone I have installed previous version of app from google play. I know that uninstalling old version of app from my phone can fix the problem but I don't want to do this because then I might lose all app specific data.
What I tried:
generating signed version of app using the same keystore.jks like previously
changing versionCode and versionName in build.grandle file and then generating new version of app
And still I have the same problem. What should I do to update my app without losing data?
There are two possibilities I can think of
You use Google Play App Signing. If you use Google Play App Signing then the signature in apps coming from Google Play will always be different to the app coming from your IDE. The only way you can get the update to work is to update the app from Google Play. The best way to do this during development is to use an "Internal test track". Google launched these at Google I/O this year and they let you update your app in seconds from Google Play. So when you have an update, don't install from your IDE, upload to Google Play internal test track, republish, and then update from Google Play. It is really quick.
You don't use Google Play App Signing, but you are trying to install your debug build instead of your release/production build. Make sure you are building the production release APK, so it is signed with the same key as the one uploaded to Google Play.
If I'm understanding correctly you want to re install the "same" apk in your phone but with some changes in the code (updates) but Android Studio can't install the new apk.
I can only think in one thing, this is the explanation:
Please remember that android has different "Build Variants" there could be many but you will always have "debug" and "production" build variants, as I can read, you have installed the one in Play Store this means that you have a "production" build variant already installed in your phone, so you need a new "production" variant version of your app with the same build data (code and name version) and the updates in the code.
Build a signed apk with the same data as the previous version (code and name version) (Just like the one you used to upload to Play Store).
Find the signed apk.
Use adb to check your connected devices, expect a list
adb devices
Use adb to install this new apk.
adb -s <device_identifier> install <apk_name_include_apk>
Following those steps should let you install what you need.
Go in your React Native > Android >app
in the app folder,
you can see a build just delete this folder and Clear React Native project by npm cache clean cmd/Terminal Command.
Now try to run I hope it will Run for some of you.
It's working for me.

Categories

Resources