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

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

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

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


当前回答

通过ADB Shell连接到Sqlite3

我还没有找到任何方法来做到这一点,在Android工作室,但我访问db与远程shell,而不是每次拉动文件。

在这里找到所有信息: http://developer.android.com/tools/help/adb.html#sqlite

1-在命令提示符中进入你的平台工具文件夹

2-输入命令adb devices获取您的设备列表

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx   device

3-连接一个外壳到您的设备:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell

4-导航到包含你的db文件的文件夹:

cd data/data/<your-package-name>/databases/

5-运行sqlite3连接到你的数据库:

sqlite3 <your-db-name>.db

6-运行你喜欢的sqlite3命令,例如:

Select * from table1 where ...;

注意:在下面可以找到更多要运行的命令。

SQLite备忘单

在SQLite数据库中查看表有几个步骤:

列出数据库中的表: .tables 列出表格的外观: . schema的表 打印整个表格: SELECT * FROM tablename; 列出所有可用的SQLite提示命令: .help

其他回答

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插件SQLScout。你可以实时查看和编辑你的应用程序数据库。

编辑:记住这是一个付费插件,但有24小时的试用,适合头痛的时候。

打开Android Studio底部的设备文件探索终端。

打开名为Data的文件夹,然后在Data内部再次打开Data文件夹。

向下滚动文件夹列表,找到带有你的.package.name的文件夹。打开文件夹your.package.name >数据库。你得到你的。databasename。右击你的。databaseName和Save as到C:/your/Computer/Directory。

进入C:/your/Computer/Directory,打开你的。databaseName with DB SQLite

经过所有的解决方案,我将建议

使用Stethos 让我们看看它有多简单

在构建中添加以下依赖项。gradle文件

implement 'com.facebook.stetho:stetho:1.5.0'
implement 'com.facebook.stetho:stetho-js-rhino:1.4.2'

然后转到mainActivity onCreate方法 添加以下行

Stetho.initializeWithDefaults(this);

这需要你

import com.facebook.stetho.Stetho;

现在在运行应用程序从android工作室,打开Chrome和地址栏类型 chrome: / /检查/

在资源选项卡>web SQL 检查数据库和表 玩它在实时容易

更新:在最近的Chrome版本中,Stethos被打破了。如果遇到问题,请尝试使用Edge开发工具代替Edge://inspect/#devices -参见:https://stackoverflow.com/a/67674265/14232521

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

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

希望能有所帮助