Running ndk-gdb with package not found error on mo

2019-01-17 12:10发布

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

7条回答
再贱就再见
2楼-- · 2019-01-17 12:38

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
查看更多
走好不送
3楼-- · 2019-01-17 12:41

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.

查看更多
Luminary・发光体
4楼-- · 2019-01-17 12:44

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

查看更多
不美不萌又怎样
5楼-- · 2019-01-17 12:48

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.

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-17 12:57

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.

查看更多
beautiful°
7楼-- · 2019-01-17 12:58

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.

查看更多
登录 后发表回答