自应用发布以来,我一直在使用Android Studio开发应用。

直到最近,一切都很好,我必须调试和检查数据库文件。由于我不知道如何直接看到数据库,当我调试生成数据库文件时,我不得不将数据库文件从我的手机导出到PC上。

为此,我必须打开DDMS >文件资源管理器。一旦我打开DDMS,我必须重新连接USB,我失去了调试线程。在检查数据库文件之后,我必须关闭DDMS并重新连接USB以回到调试模式。

这太复杂了。有人有更好的方法来做到这一点在Android Studio(我知道它更容易在Eclipse) ?


当前回答

如果你想在ANDROID STUDIO中浏览你的数据库,这是我正在使用的:

去文件/设置/插件,看看这个:

... 在重新启动Android Studio之后,你可以像这样选择你下载的数据库文件:

…点击“Open SQL Console”图标,你就会看到Android Studio中数据库的漂亮视图:

其他回答

它是其他答案加加号的组合

Install DB Browser for SQLite Get the exact location from Device File Explorer for MyBase.db something like "/data/data/com.whatever.myapp/databases/MyBase.db" Set the project window from Android to Project - so you can see the files (build.gradle, gradle.properties,...etc) In Project window right click and chose Open in Terminal In terminal you are now in the root director of your application from the hardisk so execute: adb pull /data/data/com.whatever.myapp/databases/MyBase.db Now on the Project window of you Android Studio you have a file "MyBase.db" Double click your db file from Project and you can now browse/edit your databases in DB Browser When you are ready just do Write Changes in DB Browser so databases are saved on hardisk In terminal with the command: adb push MyBase.db /data/data/com.whatever.myapp/databases/MyBase.db you just send from the Hardisk to device the edited database.

随着Android Studio 4.1 Canary和Dev预览版的发布,你可以使用一个名为

数据库检查员

安装AS 4.1+,运行应用程序,打开数据库检查器,现在你可以在数据库检查器面板的左侧查看你的数据库文件,然后选择表格查看内容。

实时查询

你可以使用run SQL选项运行你的查询,或者如果你使用Room,然后打开数据库检查器并运行应用程序,你可以通过单击@Query注释左侧的运行按钮在你的界面中运行DAO查询。

最简单的方法是使用Android调试数据库库(GitHub上的7.7k星)。

优点:

快速实现 查看所有数据库和共享首选项 直接编辑、删除、创建数据库值 在给定的数据库上运行任何SQLite查询 在数据中搜索 下载数据库 添加自定义数据库文件 不需要根设备

使用方法:

添加debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'来构建。gradle(模块); 启动应用程序; 找到日志中的调试链接(在LogCat中)(即D/DebugDB:在浏览器中打开http://192.168.232.2:8080,链接会不一样)并在浏览器中打开; 享受强大的调试工具!

重要的是:

不幸的是,它不能与模拟器一起工作 如果您通过USB使用它,请运行adb forward tcp:8080 tcp:8080 你的Android手机和笔记本电脑应该连接到同一个网络(Wifi或局域网)

欲了解更多信息,请访问GitHub上的图书馆页面。

事实上,我很惊讶没有人给出这个解决方案:

看看Stetho。

为了不同的目的(其中之一是数据库检查),我在多个场合使用过Stetho。在实际的网站上,他们还讨论了网络检查和查看视图层次结构的功能。

它只需要一个小小的设置:1个gradle依赖项添加(你可以注释掉生产构建),几行代码来实例化Stetho,和一个Chrome浏览器(因为它使用Chrome devtools来做所有事情)。

更新: 您现在可以使用Stetho查看Realm文件(如果您使用Realm而不是SQLite DB): https://github.com/uPhyca/stetho-realm

更新2: 现在可以使用Stetho查看Couchbase文档:https://github.com/RobotPajamas/Stetho-Couchbase

更新# 3: Facebook正致力于将Stetho的所有功能添加到其新工具Flipper中。Flipper已经具备了Stetho的许多功能。 所以,现在可能是做出改变的好时机。https://fbflipper.com/docs/stetho.html

Follow the above steps to open the database folder of your app in Android Device explorer and in there you can see six files, The first three is named as android and the last three is named as your database name. You only have to work with the last three files, save these three files at your preferred location. You can save these files by right-clicking to the file and click save as button (like I have my database named as room_database and so three files are named as room_database, room_database-shm, and room_database-wal. Rename the corresponding file as follows:-

1)从room_database到room_database.db 2) room_database-shm到room_database.db-shm 3) room_database-wal到room_database.db-wal

现在在任何SQLite浏览器中打开第一个文件,这三个文件都将被填充到浏览器中。