Question

I have an issue with my Ubuntu installation of genymotion. Mainly I am unable to debug my database since both through DBMS in eclipse and adb in shell I can not view content of /data/ folder. There are no files shown.

I log through adb by cd to /sdk/platform-tools and typing ./adb shell su . I see that tab is not working, so I blindly type the path. Anyways I am not able to pull db, maybe I'm doing something wrong with commands.

Through DBMS i try to connect but data folder does not display content.

On Emulator everything works smoothly, but emulator is slow and I would rather use genymotion.

Any suggestions how to deal with this problem?

Était-ce utile?

La solution 4

I managed to kind off go around the issue so I post my solution in case someone will find it helpful.

Previously I've been creating VM's with no google apis, superUser app crashed every time I wanted to root the phone.

so I created VM that is provided with google play and downloaded SQL Debugger App. I also use this code in my test suite and so I fetch db to SD-card at the end of every test I run. That way I don't need to have superuser permissions.

public static void copyDbToSd(Context context) {
    File dbFile = context.getDatabasePath((String) DatabaseHandler.DATABASE_NAME);


    InputStream myInput;
    try {
        myInput = new FileInputStream(dbFile);
        OutputStream myOutput = new FileOutputStream(
                Environment.getExternalStorageDirectory() 
                + java.io.File.separator 
                + "database.db");

        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (FileNotFoundException e) {
        Log.e(TAG, "Exception: ", e);
    } catch (IOException e) {
        Log.e(TAG, "Exception: ", e);
    }

}

where DatabaseHandler.DATABASE_NAME is name of my database I set at creating db.

Autres conseils

I don't have the problem you are talking about, the default shell user on Genymotion is root, so it should not happen. Despite everything, you can use run-as command to access your data directly.

To make it short. Your app's data folder is protected by your app's user rights. The default shell user don't have right access to the app's folder. You can change the user that the shell is using thanks to the run-as command.

  1. Open a shell: adb shell
  2. Then type: run-as your.package.name

This command will change the shell user to the user of your app. So you will have the right to read and write on the app's data. You will also be redirected to your app's data folder: /data/data/you.package.name

When it is done you can browse your files easily.

Notice: Your app has to be built as debug to be able to use this command. It is supposed to be displayed on the device processes list on DDMS.

Run emulator on your local computer, then

localuser:~ localhost$ adb shell
shell@android:/ $ su
shell@android:/ # cp /data/data/your.package.name/databases/your_database.db /mnt/shell/emulated/0/Download/your_database.db
shell@android:/ # exit
shell@android:/ $ exit
localuser:~ localhost$ adb pull /mnt/shell/emulated/0/Download/your_database.db ~/your_database.db

What it does is:
1. Connects to the emulator
2. Requests superuser permissions
3. Copies the file that is only available to superuser to a public directory (Downloads in this case)
4. Pulls the file from public folder (Downloads) to your local machine home directory; you can also perform this step from eclipse gui.

You've to set permissions to that folder / file, then you can pull easily:

adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"

adb pull /data/data/package.name/databases/file .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top