Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Persistence Using SQLite for Structured Data Using sqlite3 to View Databases

Jessica Soruco
Jessica Soruco
5,843 Points

permission denied after openning adb shell and then cd data/data

So I typed command adb shell then I try doing what they say at 02:13 in video: cd data/dataand I get error message: opendir failed, Permission denied, so I tried with sudo cd data/data and get the followig error: sudo: permission denied

Alex Lowe
Alex Lowe
15,147 Points

Copy and pasted directly from SO u/abbood:

before we start, do you have a rooted phone? if not, I strongly suggest that it's time you make the jump. 99% of the tutorials that help you to do this require that you have a rooted phone (I know b/c I spent about an hour searching for a way to do it without having a rooted phone.. couldn't find any..) also if you think about it, your iPhone also has to be rooted to do this same task. So it's totally reasonable. More about rooting at end of answer.

from your command line type:

adb shell this takes you to your android shell comand line (you should see something like this: shell@android:/ $ now type:

shell@android:/ $run-as com.domain.yourapp this should take you directly to the data directory of com.domain.yourapp:

shell@android:/data/data/com.domain.yourapp $ if it doesn't (ie if you get an error) then you probably don't have a rooted phone, or you haven't used your root user privileges. To use your root user privileges, type su on the adb command line and see what happens, if you get an error, then you're phone is not rooted. If it's not, root it first then continue these instructions.

from there you can type ls and you'll see all the directories including the dbs:

shell@android:/data/data/com.domain.yourapp $ ls

cache databases lib shared_prefs
after that you can use sqlite3 to browse the dbase.. if you don't have it installed (you can find it out by typing sqlite3, if you get command not found then you'll have to install it. To install sqlite, follow instructions here.

about rooting: if you've never rooted your phone before, and you're worried about it screwing your phone, I can tell you with full confidence that there is nothing to worry about. there are tonnes of quick and easy phone rooting tutorials for pretty much all the new and old models out there, and you can root your phone even if you have a mac (I rooted my s3 with my mac).

2 Answers

Bryner Toma
Bryner Toma
25,748 Points

Your device must be rooted.
In the Developer Options menu of your device ensure:

  1. Developer Options are enabled
  2. Android debugging is enabled
  3. ADB has permissions in Root access

Enter adb shell and enter su (meaning type su and hit enter in a windows machine) to enable Super User mode. You should see a # at the end of the prompt confirming your shell is in Super User mode. Then continue with the instructions in this video.

from: http://stackoverflow.com/questions/31672359/sqlite-error-unable-to-open-database-data-data-packagename-databases-sampledb

Dmitry Serov
Dmitry Serov
6,051 Points

You can try with the emulator, worked for me.