That’s it! Hope it shed some light on SQLite debugging and made your Android journey a little more enjoyable. In our case, triggers were working incorrectly in conjunction with multiple transactions, so the fix was quite simple: wrap one of our repository update methods in one transaction. You can read about that by checking an extensive article from Vasya Drobushkov. The reason was lying on how Room handles Kotlin Coroutines Flow return type by using SQL Triggers. Using the above trick, we quickly identified the problem and fixed it. Here we have a simple SQL select, transaction begin and SQL update. 13:27:17.757 9094-9193/my.application V/SQLiteStatements: /data/user/0/my.application/databases/my_database: "BEGIN EXCLUSIVE " 13:27:17.755 9094-9194/my.application V/SQLiteStatements: /data/user/0/my.application/databases/my_database: "SELECT * FROM contacts WHERE id = 4" Now you can finally launch your app and see the logs in the logcat. Now the only thing we need is to restart the shell, by executing these commands (emulator will restart): Since emulator with Google Play services is a production build, you will receive "adbd cannot run as root in production builds"Īdb should answer you with "restarting adbd as root” and you will be good to go. ⚠️ Important: your emulator should be installed without Google Play services. If you use an emulator, execute the following command: You can easily do this using ADB commands, but your phone/emulator has to be rooted. Why so? Since SQLite service was already launched when we set our new log tag value, it was not taken into account, because we need to restart the service first. If we launch our application right now and do something that impacts the database, we will not see any logs in our logcat. If it printed “VERBOSE”, you’re good to go. To double-check, you can execute this command to see if the value was correctly set.Īdb shell getprop VERBOSE is the upper level of logging - everything that can be logged will be logged.Īdb shell setprop VERBOSE In our case, I wanted to see SQLite statements that Room is generating, so it will look like this. Instead of %TAG%, put the tag you want to be logged. To enable logging aforementioned logs in logcat, you would need to fire up your command line interface and execute the following command. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |