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

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

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

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


当前回答

这可能不是你想要的答案,但我没有更好的方法从手机下载DB。我的建议是确保您使用的是这种迷你ddms。它将超级隐藏,但如果你不点击非常小的伪装框在程序的左下角。(试着在它上面盘旋,否则你可能会错过它。)

同样,下拉菜单显示没有过滤器(右上)。它实际上有很多不同的方法,你可以通过PPID,名称等监视不同的进程/应用程序。我一直用这个来监控手机,但请记住,我不是在做那种需要120%肯定数据库没有做一些不寻常的事情的开发工作。

希望能有所帮助

其他回答

这是一个非常古老的问题,我的答案与上面的一些答案相似,但做得更快。下面的脚本是Mac,但我相信有人可以修改它为Windows。

1)在Mac上打开脚本编辑器(你可以在Spotlight中搜索脚本编辑器) 2)复制粘贴下面的文本,并修改你的SDK路径,包名等(见下文) 3)保存脚本!!

这是它!只需按下顶部的播放按钮,即可获得更新后的数据库文件,该文件将在您的桌面上。

替换下面脚本中的内容:

Path_to_my_sdk ==>>把完整的路径到你的SDK My_package_name ==>应用程序的>包名称 myDbName.db ==>数据库的>文件名

set getLocalDb to "path_to_my_sdk/platform-tools/adb shell run-as my_package_name chmod 777 databases && path_to_my_sdk/platform-tools/adb shell run-as my_package_name chmod 777 databases/myDbName.db && path_to_my_sdk/platform-tools/adb shell run-as my_package_name cp databases/myDbName.db /sdcard/myDbName.db && path_to_my_sdk/platform-tools/adb pull /sdcard/myDbName.db /Users/User/Desktop/myDbName.db"
do shell script getLocalDb

希望这能帮助到一些人。

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 4.1及更高版本中…

1.在运行API级别26或更高的模拟器或连接设备上运行应用程序。

2.在菜单栏中选择“View > Tool Windows > Database Inspector”。

3.从下拉菜单中选择正在运行的app进程。

4.当前运行的应用程序中的数据库显示在“数据库”窗格中。展开要检查的数据库的节点。

最后,我找到了一个最简单的解决方案,不需要打开DDMS。

实际上,解决方案是基于@Distwo提到的,但它不必那么复杂。

首先,记住数据库文件在设备中的路径,它应该始终相同。 例如我的是:/data/data/com.XXX.module/databases/com.XXX.module.database

其次,执行这个命令,将数据库文件拉到PC上

 adb pull /data/data/com.XXX.module/databases/com.XXX.module.database /Users/somePathOnYourPC/

您需要做的就是复制并存储这个命令,然后您就可以一次又一次地使用它。

第三,如果你得到了Permission Denied或类似的情况,只需在前面的命令之前运行adb root。

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

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.