Running ndk-gdb with package not found error on motorola phone
Asked Answered
A

7

14

I have a C++ Android application that I'm trying to debug with ndk-gdb. The application does use multiple threads, but supposedly r5 of the ndk supports multiple threads. Also, I'm not even getting to the point where gdb starts up. I run the command:

ndk-gdb --start --force --verbose

It then finds the proper path for the ndk and sdk (or at least adb), and the needed ABIs and whatnot.

$ ndk-gdb --start --force --verbose
Android NDK installation path: /home/leif/eclipse/android-ndk-r5b
Using default adb command: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/home/leif/eclipse/android-sdk-linux_86/platform-tools/adb'
Using auto-detected project path: .
Found package name: net.leifandersen.mobile.android.marblemachine
ABIs targetted by application: armeabi
Device API Level: 10
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi

It then looks for gdb server, and finds it, including the proper PID, followed by starting the activity.

But then, it tells me that the the package cannot be found:

Setup network redirection
## COMMAND: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb shell run-as <package name> lib/gdbserver +debug-socket --attach 16040
## COMMAND: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb forward tcp:5039 localfilesystem:run-as: Package '<package name>' is unknown/debug-socket

It then spits out what you would get if you improperly use adb (the help file), followed by:

ERROR: Could not setup network redirection to gdbserver?
       Maybe using --port=<port> to use a different TCP port might help?
run-as: Package '<package name>' is unknown

I looked into /data/system/packages.list, and yes, my apk is most certainly in there, and the location it's pointing to is correct on the file system. So that's not the problem.

This tutorial: http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/ recommends deleting and reinstalling, as well as cleaning your eclipse build.

I didn't use eclipse to build the package, but I did clean everything out and compile from scratch, deleted, and reinstalled to no luck.

Has anyone had similar problems, and how did you resolve them? Thank you.

Edit: Oh, and I have tried a different port to no avail, there does not appear to be anything on 5039 (the default port) anyway. And afaik, I don't have any firewalls blocking that connection. I'm developing on Ubuntu 11.04 as well.

Edit2: Hmm...it looks like with the new ndk (r5c), the error message has now changed too:

ERROR: Could not extract package's data directory. Are you sure that
       your installed application is debuggable?

And yes, debuggable is set to true in the manifest, and all of the native code is built with:

LOCAL_CFLAGS           := -Wall -g
LOCAL_LDFLAGS          := -Wl,-Map,xxx.map
Alfons answered 28/5, 2011 at 0:47 Comment(2)
Does '$ adb shell run-as net.leifandersen.mobile.android.marblemachine ls' work?Threnode
Nope, I get: run-as: Package 'net.leifandersen.mobile.android.marblemachine' is unknown, also, it looks like there is a bug report for this sort of thing, but the package isn't three levels deep: code.google.com/p/android/issues/detail?id=13965. Also, as I said, the package is still listed in /data/system/packages.list.Alfons
T
15
run-as: Package 'net.leifandersen.mobile.android.marblemachine' is unknown

Thus, unfortunately, your device is not able to be used with ndk-gdb, because run-as doesn't work. If you want to use that device, you must have root privilege.

EDITED:

Modify ndk-gdb script to get rid of the dependency of run-as. It works only on root privilege ('adb shell whoami' should be 'root').

--- ndk-gdb 2011-02-24 16:55:07.000000000 +0900
+++ ndk-gdb-root    2011-06-09 08:35:04.000000000 +0900
@@ -465,7 +465,7 @@
 log "Using app out directory: $APP_OUT"

 # Find the <dataDir> of the package on the device
-DATA_DIR=`adb_shell run-as $PACKAGE_NAME /system/bin/sh -c pwd`
+DATA_DIR="/data/data/$PACKAGE_NAME"
 log "Found data directory: '$DATA_DIR'"
 if [ $? != 0 -o -z "$DATA_DIR" ] ; then
     echo "ERROR: Could not extract package's data directory. Are you sure that"
@@ -543,7 +543,7 @@

 # Launch gdbserver now
 DEBUG_SOCKET=debug-socket
-run $ADB_CMD shell run-as $PACKAGE_NAME lib/gdbserver +$DEBUG_SOCKET --attach $PID &
+run $ADB_CMD shell "(cd $DATA_DIR; lib/gdbserver +$DEBUG_SOCKET --attach $PID)" &
 if [ $? != 0 ] ; then
     echo "ERROR: Could not launch gdbserver on the device?"
     exit 1
Threnode answered 8/6, 2011 at 4:56 Comment(6)
With root privileges, how would I go about fixing the problem (or even figuring out what the problem is in the first place)? Thank you.Alfons
(Well, not on r5c, but r5b works fine, and I would imagine that a similar edit would work for r5c).Alfons
"Thus, unfortunately, your device is not able to be used with ndk-gdb, because run-as doesn't work. If you want to use that device, you must have root privilege." - No, there is actually a bug in run-as. You do not need root privileges. See my answer.Gianina
You Sir are my hero. Ballads should be sang about you!Hopfinger
run-as is apparently completely broken on 4.3: code.google.com/p/android/issues/detail?id=58373 . The 'FutureRelease' status means that the next Android version should resolve it, presumably the upcoming 4.4.Bucella
Thank you @Bucella I have nexus4 4.3 updated - and am having same issue. Figured this out after 2 days reading your comment. So to do native debugging Either I root my nexus4 and try or apply android 4.3 fresh image (loose all data on handset) or wait a little for android 4.4 update.Davinadavine
G
4

There is a bug with run-as, it will fail if you have too many apps installed. I was able to work around this problem by removing some apps from my Evo 4G. I found this in the NDK discussion groups - http://groups.google.com/group/android-ndk/browse_thread/thread/ae9e8d5fe2716ae6?pli=1

Gianina answered 13/11, 2011 at 4:15 Comment(0)
B
2

I had the same issue today with Samsung Galaxy S running MIUI rom. ndk-gdb always reported "Could not extract package's data directory. Are you sure that your installed application is debuggable?"

It turned out the reason is that run-as not working due to /data/data symlink. Cyanogen is used in the customized ROM. Removing the symbolic link and move all files from /datadata to /data/data solved the problem.

Cyanogen 2.3 fix:

ndk-gdb relies on the 'run-as' command, which itself makes a number of checks on the /data/data directory. In Cyanogen 2.3, it's a symlink, and run-as fails with a cryptic message, and ndk-gdb fails in return with [2]:

ERROR: Could not extract package's data directory. Are you sure that
       your installed application is debuggable?

A work-around is to recreate /data/data with symlink :

cd /data/data /datadata.break-run-as
mkdir -m 771 /data/data/
chown system: v
mv /datadata/* /data/data/

http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Android_NDK

http://forum.cyanogenmod.com/topic/27657-run-as-not-working-due-to-datadata-symlink/

Hope it helps others with similar issue. Check to see if run-as works as expected or not. It's not because your binary is not debuggable. ndk-gdb's error message is very misleading.

Burthen answered 20/10, 2012 at 0:18 Comment(0)
S
1

Had a similar problem and running:

adb shell run-as com.mypackagename /system/bin/sh -c pwd

would output:

run-as: Package 'com.mypackagename' has corrupt installation

fix was to uninstall on device then reinstall from command line via:

adb install MyApkFile.apk
Spasmodic answered 14/11, 2012 at 8:6 Comment(0)
J
0

I also experienced this problem and discovered that it can be caused by short package names!

When testing on an Android 2.2 system with an application that had a package with 3 levels (e.g: a.b.c) ndk-gdb would not work. Changing the package to have 4 or more levels (e.g. a.b.c.d) or running on Android 2.3 or later resolved the issue.

see http://code.google.com/p/android/issues/detail?id=13965 for more information.

Joo answered 29/2, 2012 at 22:35 Comment(0)
F
0

There is still another posibility for this problem to occur: if you have previously installed your application as a system app (in /system/app), uninstalled it and then installed it once again as a normal application. In that case it is posible that there is still some files remaining that your application cannot access because it has no permissions.

I solved it by uninstalling my application and manually removing every piece of information related to it (with adb shell and root privileges). As far as I know, that comprises:

  • Everything under /data/data/<your app package>
  • The file named /data/dalvik-cache/* <your app package>*

After installing it again, I was able to debug the application again.

Forney answered 14/1, 2013 at 15:0 Comment(0)
B
0

In case anyone is using Samsung Galaxy S4/... and got 4.4.2 (latest stock rom - by now at all countries) - you got screwed! Samsung bug. So root as explained in one of the answers above, or get another device... Another solution is to revert to Android 4.2.2 (not 4.4.2) - pre 4.3 version which started this issue.

Brawn answered 18/1, 2015 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.