[GUIDE] How to enable adb backup for any app changing android:allowBackup

Search This thread

scandiun

Senior Member
Jul 12, 2010
1,903
983
Some applications can't be backed up by adb backup because the option is disabled on the AndroidManifest.xml of the apk. To workaround this, it is required to set android:allowBackup to true in the AndroidManifest.xml.

The application I will be patching is Signal Private Messenger, which by default doesn't allow adb backups (security reasons, I guess). Also, it's an open source application:
Signal Private Messenger (Play Store)
Signal Private Messenger (GitHub)

CHECKING FLAG_ALLOW_BACKUP
The first step is to check if the flag FLAG_ALLOW_BACKUP is present. It can be done several ways, but the easiest one is to use System Info for Android or System Info Pro for Android to check the flags of any desired application. Of course using Windows or Linux you can use script to auto-check for any number of apks.
You will see that in the app "Signal Private Messenger" the flag is missing with the official version:

2dj2peq.jpg


Analyst also displays FLAGS per app. In this screenshot you can see Signal already patched:

fuymg5.jpg


APK EASY TOOL (WINDOWS APPLICATION)
To decompile, compile and sign the modified apk, the APK Easy Tool is the best to go, all in one with no complication. It requires java SDK installed and "java" and "javac" to be present on your PATH:
[TOOL] APK Easy Tool v1.2 for Windows (GUI tool, friendly)

Once you've executed "APK Easy Tool v1.2.exe", go to Options and configure "Decompiled directory" and "Compiled directory". You can just hit "Setup directories for me" and the folders will be set automatically to default locations:

qn1jc3.jpg


Then go to the main tab of the program and leave checked "Sign APK after compile". Hit "Select" on "APK File to work on" and Decompile:

104m49v.jpg


Now on your "Decompiled APKs" folder (you can use directly the button on the main windows of the program), open the file AndroidManifest.xml with a text editor. Notepad++ is highly recommended.

Then replace
android:allowBackup="false"
with
android:allowBackup="true"

After that, save the file and close the text editor. Now go back to APK Easy Tool and hit Compile to build the modified version of Signal Private Messenger. It will be present on the "Compiled directory".

APK EDITOR PRO (ANDROID APPLICATION)
APK Editor Pro is the way to go if you want to edit the file directly on the smartphone. First, you need to get the Signal apk from the smartphone, with some app like APK Extractor Pro.

Open the extracted Signal apk with the apk editor and edit the AndroidManifest.xml. Save and it will automatically compile and sign the new version.

Note that APK Editor Pro is very prone to errors, so it's highly recommender to use the APK Easy Tool instead. Just try and error.

REINSTALL APP
To install on android the patched apk, you must first uninstall your previous version, and this is because the key used to sign the apk is different. If you try to install one app itself with a different signing key, you will get this error: [INSTALL_FAILED_ALREADY_EXISTS]

Now you can see that FLAG_ALLOW_BACKUP is present:

23mncwp.jpg


There are some things to have in mind when using apks signed with unofficial keys:
  • The app will no be updated anymore automatically from Google Play Store or any other store, because you are using a custom key. You must surveil periodically the store where you get the updates, download the newer apk, patch it and update it. The developer may or may not modify flags with future updates.
  • You can uninstall the patched app at any time to reinstall the official one from Play Store, but you will lose app's data if you don't perform a valid backup before.
  • Signing keys have an expiration date. The one used by APK Easy Tool is valid for a lot of years so shouldn't be a worry.
  • The apks generated by APK Easy Tool are not zipaligned, but they will work perfectly the same. The only difference is that they will consum a little more of RAM.
  • If you modify several apks, it's better to use the same signing key for ease of updating.

OTHER METHODS AND LINKS
There are a lot of methods to decompile, edit, recompile, sign and zipalign apks. I will provide some useful links with other software and development information:

https://developer.android.com/studio/command-line/zipalign.html
http://stackoverflow.com/questions/19543520/zipalign-verification
http://stackoverflow.com/questions/8300822/android-how-to-find-which-platform-version-an-apk-targets
https://github.com/WhisperSystems/Signal-Android/wiki/How-to-build-Signal-from-the-sources
https://shatter-box.com/knowledgebase/android-apk-signing-tool-apk-signer/
[IDE][3.x] APK Studio - IDE for Reverse Engineering Android APKs
Decompile, Edit, and Recompile in One Tool with APK Studio
Idea: Hook "android:allowBackup" in AndroidManifest.xml
[XPOSED][MOD] Backup All Apps
[INDEX] Xposed Modules Collection | Post Modules' Requests Here!
ADB Backup and Restore not all it's cracked up to be.
 
Last edited:

Praetoriani

Senior Member
Feb 10, 2013
113
17
Munich
backup of apps fails despite android: allowBackup="true"

I tried to backup some apps using following ADB-Command:
adb backup -apk -obb -noshared apk.package.name -f C:\Destination\Folder\package_backup.ab
But it didn't work for all my apps.

I started searching for an explanation and a solution for my Problem. Then I found your guide and followed the instructions.
But when I decompiled some of these apps I wasn't able to create a backup, I recognized that some of them had the flag android:allowBackup="true"

Here are a few of these apps (just to name a few):
» app.WTInfoTech.WorldAroundMeLite.apk
» appplus.mobi.lockdownpro.apk
» cn.wps.moffice_eng.apk
» color.dev.com.pink
In reality, there are far more apps than just four.
There are certainly around 40-50 apps that can not be backed up using ADB (even though they have the appropriate flag in the AndroidManifest.xml)

I am using the latest Plattform Tools for Windows (r28.0.1) downloaded from here

Can someone explain to me, why I cannot backup these apps? Even if they have the android:allowBackup="true" flag?
Am I doing something wrong? Or is there some kind of a magic trick that I don't know?

I would be very happy if someone could help me with this problem.
 

dazoe

Member
Oct 20, 2010
28
5
OnePlus 5
OnePlus 6T
I've been having this problem as well. I noticed that not all apps are backed up using the all flag etc.
I think it boils down to if the app uses a backup agent. Looking at the logcat when attempting to backup ConnectBot using the command adb -apk -obb -f backup.ab org.connectbot It said connect bot is Key-Value and just silently skips it. When using the command adb -apk -obb -keyvalue -f backup.ab org.connectbot It will actually backup some data, but it will not backup the apk.
I don't really have a solution just wanted to share some observations.

I tried to backup some apps using following ADB-Command:
adb backup -apk -obb -noshared apk.package.name -f C:\Destination\Folder\package_backup.ab
But it didn't work for all my apps.

I started searching for an explanation and a solution for my Problem. Then I found your guide and followed the instructions.
But when I decompiled some of these apps I wasn't able to create a backup, I recognized that some of them had the flag android:allowBackup="true"

Here are a few of these apps (just to name a few):
» app.WTInfoTech.WorldAroundMeLite.apk
» appplus.mobi.lockdownpro.apk
» cn.wps.moffice_eng.apk
» color.dev.com.pink
In reality, there are far more apps than just four.
There are certainly around 40-50 apps that can not be backed up using ADB (even though they have the appropriate flag in the AndroidManifest.xml)

I am using the latest Plattform Tools for Windows (r28.0.1) downloaded from here

Can someone explain to me, why I cannot backup these apps? Even if they have the android:allowBackup="true" flag?
Am I doing something wrong? Or is there some kind of a magic trick that I don't know?

I would be very happy if someone could help me with this problem.
 

Praetoriani

Senior Member
Feb 10, 2013
113
17
Munich

@dazoe
THX for sharing your knowledge :good:
I'm going to check my logcat as well for these apps adb does not back up :)
I can give you a short guide on how to extract/backup an apk of a specific package:

1) If you don't know the package-name, you can create a list of all installed packages (sorted in alphabetical prder without app names)
adb shell pm list packages -f | sed -e 's/.*=//' | sort

2) Now look for the desired app you want to extract/backup the apk from. Then run following command:
adb shell pm path com.example.someapp
You will get an output which will look something like the following:
package:/data/app/com.example.someapp-1/base.apk

3) With this information you can simply perform a pull-command like the following:
adb pull -a -p /data/app/com.example.someapp-1/base.apk C\LOCAL\PATH\TO\YOUR\BACKUP\com.example.someapp-1/base.apk

Hope that I could help you with this little guide
;)
 
  • Like
Reactions: is0xxx

chris_v

Member
Apr 5, 2008
25
6
I patched the apk I want to backup, but before I uninstall the original and install the patched, are there any other methods that will allow me to restore my original appdata? Since uninstalling the original will remove that appdata. I'm not rooted.
 

wsuh

Member
Dec 22, 2014
6
2
so whats the point if you have to uninstall the app and reinstall using the new apk? itll wipe the data of the app you're trying to back up

is there any way to do this without wiping?
 

scandiun

Senior Member
Jul 12, 2010
1,903
983
I ran all of the commands below to uninstall the app in question while keeping my data which I want to backup:
Code:
adb shell pm uninstall -k --user 0 my.app.name
adb shell pm uninstall -k my.app.name
adb shell cmd package uninstall -k my.app.name
adb uninstall -k my.app.name
These commands probably all call the same procedure under the hood but I just wanted to make sure the app really gets uninstalled. So either one of these commands should do the job.

I guess that part worked and it actually preserved most of my private data.

Now the problem:
When I try to reinstall the modded .apk file I get this error:

Code:
adb: failed to install gen_signed.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package my.app.name signatures do not match the previously installed version; ignoring!]
You can only reinstall app with same signature, if there is some data left. If you uninstall totally, you can install with different signature (but you lose data). If you need to get the data you can try to root without formatting.
 

scandiun

Senior Member
Jul 12, 2010
1,903
983
Hi @scandiun
How can I root stock HTC U11+ running Oreo without formatting internal storage?
As soon as I unlock the bootloader all data gets wiped!?
I need to backup some important app data before I can unlock bootloader and then install TWRP/Magisk.
As you can see I am in a dilemma. Thanks for chiming in.

I have no idea about that phone. Most of times, it's now possible unless there is a bug which allows to gain root access while running android. There are 4 ways that you can try:
  1. Try some app which allows to root the phone temporarily while it's running (without the need for any bootloader unlock). For the LG G2 there was AutoRec and Towelroot.
  2. Request HTC a special update or feature for your device (for your specific IMEI/serial number) so they allow you to update or unlock bootloader without data format.
  3. Contact the app developer and request an update for you with android:allowBackup enabled. If the developer is still alive and is willing to do so, because you just need his signing key. Sometimes it's done by Google servers instead of the developer itself.
  4. Wait for your device to oficially update to android 11, since that version will ignore that flag when syncing all phone data to a new phone. There you could sync to a rooted phone with LineageOS and recover the data. Request HTC to update that device
Android 11 forces apps to support local backups but not cloud backups
 
  • Like
Reactions: lebigmac

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    Some applications can't be backed up by adb backup because the option is disabled on the AndroidManifest.xml of the apk. To workaround this, it is required to set android:allowBackup to true in the AndroidManifest.xml.

    The application I will be patching is Signal Private Messenger, which by default doesn't allow adb backups (security reasons, I guess). Also, it's an open source application:
    Signal Private Messenger (Play Store)
    Signal Private Messenger (GitHub)

    CHECKING FLAG_ALLOW_BACKUP
    The first step is to check if the flag FLAG_ALLOW_BACKUP is present. It can be done several ways, but the easiest one is to use System Info for Android or System Info Pro for Android to check the flags of any desired application. Of course using Windows or Linux you can use script to auto-check for any number of apks.
    You will see that in the app "Signal Private Messenger" the flag is missing with the official version:

    2dj2peq.jpg


    Analyst also displays FLAGS per app. In this screenshot you can see Signal already patched:

    fuymg5.jpg


    APK EASY TOOL (WINDOWS APPLICATION)
    To decompile, compile and sign the modified apk, the APK Easy Tool is the best to go, all in one with no complication. It requires java SDK installed and "java" and "javac" to be present on your PATH:
    [TOOL] APK Easy Tool v1.2 for Windows (GUI tool, friendly)

    Once you've executed "APK Easy Tool v1.2.exe", go to Options and configure "Decompiled directory" and "Compiled directory". You can just hit "Setup directories for me" and the folders will be set automatically to default locations:

    qn1jc3.jpg


    Then go to the main tab of the program and leave checked "Sign APK after compile". Hit "Select" on "APK File to work on" and Decompile:

    104m49v.jpg


    Now on your "Decompiled APKs" folder (you can use directly the button on the main windows of the program), open the file AndroidManifest.xml with a text editor. Notepad++ is highly recommended.

    Then replace
    android:allowBackup="false"
    with
    android:allowBackup="true"

    After that, save the file and close the text editor. Now go back to APK Easy Tool and hit Compile to build the modified version of Signal Private Messenger. It will be present on the "Compiled directory".

    APK EDITOR PRO (ANDROID APPLICATION)
    APK Editor Pro is the way to go if you want to edit the file directly on the smartphone. First, you need to get the Signal apk from the smartphone, with some app like APK Extractor Pro.

    Open the extracted Signal apk with the apk editor and edit the AndroidManifest.xml. Save and it will automatically compile and sign the new version.

    Note that APK Editor Pro is very prone to errors, so it's highly recommender to use the APK Easy Tool instead. Just try and error.

    REINSTALL APP
    To install on android the patched apk, you must first uninstall your previous version, and this is because the key used to sign the apk is different. If you try to install one app itself with a different signing key, you will get this error: [INSTALL_FAILED_ALREADY_EXISTS]

    Now you can see that FLAG_ALLOW_BACKUP is present:

    23mncwp.jpg


    There are some things to have in mind when using apks signed with unofficial keys:
    • The app will no be updated anymore automatically from Google Play Store or any other store, because you are using a custom key. You must surveil periodically the store where you get the updates, download the newer apk, patch it and update it. The developer may or may not modify flags with future updates.
    • You can uninstall the patched app at any time to reinstall the official one from Play Store, but you will lose app's data if you don't perform a valid backup before.
    • Signing keys have an expiration date. The one used by APK Easy Tool is valid for a lot of years so shouldn't be a worry.
    • The apks generated by APK Easy Tool are not zipaligned, but they will work perfectly the same. The only difference is that they will consum a little more of RAM.
    • If you modify several apks, it's better to use the same signing key for ease of updating.

    OTHER METHODS AND LINKS
    There are a lot of methods to decompile, edit, recompile, sign and zipalign apks. I will provide some useful links with other software and development information:

    https://developer.android.com/studio/command-line/zipalign.html
    http://stackoverflow.com/questions/19543520/zipalign-verification
    http://stackoverflow.com/questions/8300822/android-how-to-find-which-platform-version-an-apk-targets
    https://github.com/WhisperSystems/Signal-Android/wiki/How-to-build-Signal-from-the-sources
    https://shatter-box.com/knowledgebase/android-apk-signing-tool-apk-signer/
    [IDE][3.x] APK Studio - IDE for Reverse Engineering Android APKs
    Decompile, Edit, and Recompile in One Tool with APK Studio
    Idea: Hook "android:allowBackup" in AndroidManifest.xml
    [XPOSED][MOD] Backup All Apps
    [INDEX] Xposed Modules Collection | Post Modules' Requests Here!
    ADB Backup and Restore not all it's cracked up to be.
    2
    so whats the point if you have to uninstall the app and reinstall using the new apk? itll wipe the data of the app you're trying to back up

    is there any way to do this without wiping?
    1

    @dazoe
    THX for sharing your knowledge :good:
    I'm going to check my logcat as well for these apps adb does not back up :)
    I can give you a short guide on how to extract/backup an apk of a specific package:

    1) If you don't know the package-name, you can create a list of all installed packages (sorted in alphabetical prder without app names)
    adb shell pm list packages -f | sed -e 's/.*=//' | sort

    2) Now look for the desired app you want to extract/backup the apk from. Then run following command:
    adb shell pm path com.example.someapp
    You will get an output which will look something like the following:
    package:/data/app/com.example.someapp-1/base.apk

    3) With this information you can simply perform a pull-command like the following:
    adb pull -a -p /data/app/com.example.someapp-1/base.apk C\LOCAL\PATH\TO\YOUR\BACKUP\com.example.someapp-1/base.apk

    Hope that I could help you with this little guide
    ;)
    1
    Hi @scandiun
    How can I root stock HTC U11+ running Oreo without formatting internal storage?
    As soon as I unlock the bootloader all data gets wiped!?
    I need to backup some important app data before I can unlock bootloader and then install TWRP/Magisk.
    As you can see I am in a dilemma. Thanks for chiming in.

    I have no idea about that phone. Most of times, it's now possible unless there is a bug which allows to gain root access while running android. There are 4 ways that you can try:
    1. Try some app which allows to root the phone temporarily while it's running (without the need for any bootloader unlock). For the LG G2 there was AutoRec and Towelroot.
    2. Request HTC a special update or feature for your device (for your specific IMEI/serial number) so they allow you to update or unlock bootloader without data format.
    3. Contact the app developer and request an update for you with android:allowBackup enabled. If the developer is still alive and is willing to do so, because you just need his signing key. Sometimes it's done by Google servers instead of the developer itself.
    4. Wait for your device to oficially update to android 11, since that version will ignore that flag when syncing all phone data to a new phone. There you could sync to a rooted phone with LineageOS and recover the data. Request HTC to update that device
    Android 11 forces apps to support local backups but not cloud backups