Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
how to export realm database, work on Android 5.0+
#!/bin/bash
ADB_PATH="/Users/lee/Library/Android/sdk/platform-tools"
PACKAGE_NAME="com.yourcompany.app"
DB_NAME="default.realm"
DESTINATION_PATH="/Users/lee/Downloads/${DB_NAME}"
NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
echo "Make sure a device is connected"
else
${ADB_PATH}/adb exec-out run-as ${PACKAGE_NAME} cat files/${DB_NAME} > ${DESTINATION_PATH}
echo "Database exported to ${DESTINATION_PATH}"
fi
@DaveChambers

This comment has been minimized.

Copy link

commented Jul 29, 2018

Nice work!

@mcmatan

This comment has been minimized.

Copy link

commented Aug 16, 2018

Wow. King.

@bfichter

This comment has been minimized.

Copy link

commented Oct 3, 2018

Super helpful, thanks!

@danielbas

This comment has been minimized.

Copy link

commented Nov 14, 2018

This is very helpful, thank you!

@locpv-ibl

This comment has been minimized.

Copy link

commented Feb 22, 2019

Nice query but this is only for debuggable package. Best android practices do say that "Your minifest file should have set debug to false". That will probably prevent from this query!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.