android 数据库debug,GitHub - amitshekhariitbhu/Android-Debug-Database: A library for debugging android ...

AndroidDebugDatabase是一个强大的库,用于在Android应用中直接通过浏览器便捷地调试数据库和共享偏好设置。它允许查看所有数据库、共享偏好数据,执行SQL查询,直接编辑数据库和偏好设置,甚至添加或删除数据。使用此库无需设备越狱,只需在app的build.gradle文件中添加依赖,并确保手机和电脑在同一网络环境下,通过ADB连接,即可在浏览器中查看和操作数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

b6efc24b695fabed4ff88fc9f5febbbc.png

Android Debug Database

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d696e646f726b732d6f70656e736f757263652d626c75652e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6a6f696e2d636f6d6d756e6974792d626c75652e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d696e646f726b73253230416e64726f696425323053746f72652d416e64726f6964253230446562756725323044617461626173652d626c75652e7376673f7374796c653d666c6174

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d392532422d627269676874677265656e2e7376673f7374796c653d666c6174

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f616d69747368656b6861726969746268752f6d6176656e2f64656275672d64622f696d616765732f646f776e6c6f61642e737667

68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f76312f6f70656e2d736f757263652e7376673f763d313032

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e737667

Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications

Android Debug Database allows you to view databases and shared preferences directly in your browser in a very simple way

What can Android Debug Database do?

See all the databases.

See all the data in the shared preferences used in your application.

Run any sql query on the given database to update and delete your data.

Directly edit the database values.

Directly edit the shared preferences.

Directly add a row in the database.

Directly add a key-value in the shared preferences.

Delete database rows and shared preferences.

Search in your data.

Sort data.

Download database.

Debug Room inMemory database.

All these features work without rooting your device -> No need of rooted device

Check out our other Open Source Projects

Using Android Debug Database Library in your application

Add this to your app's build.gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'

Using the Android Debug Database with encrypted database

debugImplementation 'com.amitshekhar.android:debug-db-encrypt:1.0.6'

And to provide the password for the DB, you should add this in the Gradle:

DB_PASSWORD_{VARIABLE}, if for example, PERSON is the database name: DB_PASSWORD_PERSON

debug {

resValue("string", "DB_PASSWORD_PERSON", "password")

}

Use debugImplementation so that it will only compile in your debug build and not in your release build.

That’s all, just start the application, you will see in the logcat an entry like follows :

D/DebugDB: Open http://XXX.XXX.X.XXX:8080 in your browser

You can also always get the debug address url from your code by calling the method DebugDB.getAddressLog();

Now open the provided link in your browser.

Important:

Your Android phone and laptop should be connected to the same Network (Wifi or LAN).

If you are using it over usb, run adb forward tcp:8080 tcp:8080

Note : If you want use different port other than 8080.

In the app build.gradle file under buildTypes do the following change

debug {

resValue("string", "PORT_NUMBER", "8081")

}

You will see something like this :

Seeing values

e4e27c24d7d234b03ac6ab00e573a8b2.png

Editing values

89b9db5bfa43f398fdcf84538c9706df.png

Working with emulator

Android Default Emulator: Run the command in the terminal - adb forward tcp:8080 tcp:8080 and open http://localhost:8080

Genymotion Emulator: Enable bridge from configure virtual device (option available in genymotion)

Getting address with toast, in case you missed the address log in logcat

As this library is auto-initialize, if you want to get the address log, add the following method and call (we have to do like this to avoid build error in release build as this library will not be included in the release build) using reflection.

public static void showDebugDBAddressLogToast(Context context) {

if (BuildConfig.DEBUG) {

try {

Class> debugDB = Class.forName("com.amitshekhar.DebugDB");

Method getAddressLog = debugDB.getMethod("getAddressLog");

Object value = getAddressLog.invoke(null);

Toast.makeText(context, (String) value, Toast.LENGTH_LONG).show();

} catch (Exception ignore) {

}

}

}

Adding custom database files

As this library is auto-initialize, if you want to debug custom database files, add the following method and call

public static void setCustomDatabaseFiles(Context context) {

if (BuildConfig.DEBUG) {

try {

Class> debugDB = Class.forName("com.amitshekhar.DebugDB");

Class[] argTypes = new Class[]{HashMap.class};

Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);

HashMap> customDatabaseFiles = new HashMap<>();

// set your custom database files

customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,

new Pair<>(new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +

"/" + ExtTestDBHelper.DATABASE_NAME), ""));

setCustomDatabaseFiles.invoke(null, customDatabaseFiles);

} catch (Exception ignore) {

}

}

}

Adding InMemory Room databases

As this library is auto-initialize, if you want to debug inMemory Room databases, add the following method and call

public static void setInMemoryRoomDatabases(SupportSQLiteDatabase... database) {

if (BuildConfig.DEBUG) {

try {

Class> debugDB = Class.forName("com.amitshekhar.DebugDB");

Class[] argTypes = new Class[]{HashMap.class};

HashMap inMemoryDatabases = new HashMap<>();

// set your inMemory databases

inMemoryDatabases.put("InMemoryOne.db", database[0]);

Method setRoomInMemoryDatabase = debugDB.getMethod("setInMemoryRoomDatabases", argTypes);

setRoomInMemoryDatabase.invoke(null, inMemoryDatabases);

} catch (Exception ignore) {

}

}

}

Find this project useful ? ❤️

Support it by clicking the ⭐ button on the upper right of this page. ✌️

TODO

Simplify emulator issue Issue Link

And of course many more features and bug fixes.

Contact - Let's become friends

License

Copyright (C) 2019 Amit Shekhar

Copyright (C) 2011 Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

Contributing to Android Debug Database

All pull requests are welcome, make sure to follow the contribution guidelines

when you submit pull request.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值