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

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

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

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


当前回答

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

看看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

其他回答

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

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

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

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

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浏览器中打开第一个文件,这三个文件都将被填充到浏览器中。

最简单的方法是连接你的设备并运行Android Studio 然后从工具栏:

视图——>工具窗口——>设备文件资源管理器 进入data/数据并找到您的包 找到你想要浏览并下载的DB文件 我推荐使用这个在线工具:https://sqliteonline.com/来查看db文件

另一种方法是使用Stetho库:

在build.gradle中添加Stello依赖: 编译com.facebook.stetho: stetho: 1.5.0的 在你的应用程序类或主活动的onCreate()上放以下一行: Stetho.initializeWithDefaults(这个); 连接您的设备,运行应用程序,并在Chrome上进入以下站点: chrome: / /检查/ #设备

就是这样。现在可以探索您的表了。

注意:建议在转移到生产环境之前删除依赖项。

在Android 4.1 Canary 5预览版中引入了新的数据库检查器,您现在可以直接从IDE - https://developer.android.com/studio/preview/features?linkId=86173020#database-inspector检查、查询、修改和调试正在运行的应用程序中的SQLite数据库

支持数据库实时查询以及- https://developer.android.com/studio/preview/features?linkId=86173020#query

从Android Studio查看数据库:

选项1:

Download and install SQLiteBrowser. Copy the database from the device to your PC: Android Studio versions < 3.0: Open DDMS via Tools > Android > Android Device Monitor Click on your device on the left. You should see your application: Go to File Explorer (one of the tabs on the right), go to /data/data/databases Select the database by just clicking on it. Go to the top right corner of the Android Device Monitor window. Click on the 'pull a file from the device' button: A window will open asking you where you want to save your database file. Save it anywhere you want on your PC. Android Studio versions >= 3.0: Open Device File Explorer via View > Tool Windows > Device File Explorer Go to data > data > PACKAGE_NAME > database, where PACKAGE_NAME is the name of your package (it is com.Movie in the example above) Right click on the database and select Save As.... Save it anywhere you want on your PC. Now, open the SQLiteBrowser you installed. Click on 'open database', navigate to the location you saved the database file, and open. You can now view the contents of your database.


选项2:

转到这个Github存储库,并按照自述文件中的说明在您的设备上查看您的数据库。你得到的结果是这样的:

就是这样。当然,在发布应用之前,你应该撤销所有这些步骤。