In the old days of Eclipse, debugging SQLite was all about exporting database files to your computer and opening them with software. Now that we’re using Android Studio, is there an easier way?
SQLScout
The installation
SQLScout is a plugin for Android Studio that can be accessed by clicking:
Setting — > Plugings — > Browse Repositories
Search for the SQLScout installation.
If it doesn’t work, you can download it here and click Install Plugin from Disk to import.
loading
After a successful installation, restart Android Studio and SQLite Exporer will appear in the right sidebar. Click “+” to open it and three options will appear:
Let’s go from the bottom up.
Local SQLite Database
If the database you want to debug is already exported to the computer, select this option to load.
Android (Download Database Locally)
Normally, we want to debug the database is on the phone, you can use this function to extract the database. Select the device you want to debug, the project package name, and the database name.
Android (Live Device Connection)
The disadvantages of the above two methods are obvious, neither of which can update the database in real time.
Live Device Connection is a new feature in SQLScout 2.0 that allows you to manage and update your database in real time.
Gradle = build.gradle = build.gradle
allprojects {
repositories {
jcenter()
maven {
url 'http://www.idescout.com/maven/repo/'}}}Copy the code
Add the following to build.gradle in module:
compile 'com. Idescout. SQL: sqlscout - server: 2.0'Copy the code
Add a line of code to the onCreate method of the started Activity:
SqlScoutServer.create(this, getPackageName());Copy the code
debugging
The entire interface is as follows:
They are:
- Database list: To debug the list of databases, expand the display database table, you can right-click to open the SQL editor.
- SQL editor: a place to enter SQL statements, support automatic completion and code highlighting.
- Data console: Displays the queried data in an Excel like format, and you can also edit the data here.
- Data diagram: Used to show the relationship between tables and fields.
Is it very easy to use, it is a miracle! But something this good works for a fee.
What if you can’t afford it? Keep reading.
Android Debug Database
This is an open source project (free), the project address is here.
Build. Gradle for module:
debugCompile 'com. Amitshekhar. Android debug - db: 1.0.0'Copy the code
Put the phone and computer in a local area network, and as the project runs, logcat will print a line like this:
D/DebugDB: Open http://XXX.XXX.X.XXX:8080 in your browserCopy the code
Copy the address to your browser and you’ll see something like this:
It is easy to understand. The columns are:
- Query: The place where SQL statements are written
- Databases: Databases
- Tables: Tables in the database
- Data: Data in a table, which can be edited and searched
It’s that simple. It’s fine.