How to Debug Database in Android?
The Android Debug Database library is a useful tool for troubleshooting databases and shared preferences in Android apps. In this article we would be looking forward to using this library and get our hand on it, so continue reading, and indulge. First thing’s first,
What’s Exactly an Android Debug Database?
Well, the answer to that is simple, In a very easy way, Android Debug Database allows you to examine databases and shared settings straight in your browser. Not only this, but the ADD also enables you to look at the structure of your database in a debuggable format, so that you could take action on your data, in a much more granular and sophisticated manner.
All these features work seamlessly, even without rooting your Android Device! Isn’t that great?
Let’s Dive in and See in Detail. What Android Debug Database is Capable of.
Here’s a List of it:
- Look through your files.
- Sort the information.
- The database may be downloaded.
- Debug the Room database in memory.
- Look through all of the databases.
- View all of the data in your application’s shared preferences.
- Edit the shared preferences directly.
- Add a row to the database directly.
- To update and delete your data, run any SQL query on the specified database.
- Edit the database values directly.
- In the shared preferences, add a key-value directly.
- Delete shared preferences and database rows.
Sounds Great, to Begin With, Let’s Start!
Step #1: Adding the dependency to your Android Project
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
Step #2: Setting the Authentication
debug { resValue("string", "DB_PASSWORD_w3wiki", "password") }
Note: If you wish to use another port than 8080, do so. Make the following changes to the buildTypes section of the app build.gradle file.
In case you missed the address log in logcat to get the address with Toast. Because this library is auto-initialized, if you wish to retrieve the address log, add the following function and call it using reflection (we have to do this to avoid build errors in release builds because this library will not be included). Just simply pop out a toast by using this:
Kotlin
public static void showingDebug(Context context) { if (BuildConfig.DEBUG) { try { Class<?> debugDB = Class.forName( "com.w3wiki.DebugDB" ); Method getAddressLog = debugDB.getMethod( "getAddressLog" ); Object value = getAddressLog.invoke( null ); Toast.makeText(context, (String) value, Toast.LENGTH_LONG).show(); } catch (Exception ignore) { // A simple catch statement! } } } |
If you want to add your own Database file then:
Kotlin
public static void applyCustomFileDBHere(Context c) { if (BuildConfig.DEBUG) { try { Class<?> w3wikiDB = Class.forName( "com.w3wiki.w3wikiDB" ); Class[] argTypes = new Class[]{HashMap. class }; Method setCustomDatabaseFiles = w3wikiDB.getMethod( "setCustomDatabaseFiles" , argTypes); HashMap<String, Pair<File, String>> customDatabaseFiles = new HashMap<>(); // set your custom database files customDatabaseFiles.put(GfGDBHelper.DATABASE_NAME, new Pair<>( new File(c.getFilesDir() + "/" + GfGDBHelper.DIR_NAME + "/" + GfGDBHelper.DATABASE_NAME), "" )); setCustomDatabaseFiles.invoke( null , customDatabaseFiles); } catch (Exception ignore) { } } } |
And just like this, you’ve added your own Android Debug Database to Your Android Project, for more insight and information visit this GitHub repository here.
Contact Us