I am returning to work on an old app that I left 7 months ago. The build that is deployed on my android is not up to date with the version control rather I have made more changes to the code in the hope of adding some functionality when I abandoned. The result is that the code running on the emulator now is different than what is running on my device. Now I want to get back to not the latest version in repository, not the one on the emulator but the one that is deployed on my device. Is there a way to find that out?
You can use the badging options of Android Asset Packaging Tool (aapt).
First you need to extract the APK from your device:
adb shell pm path com.example
The output will be like package:/data/app/com.example-2.apk
Then pull the APK with this command:
adb pull /data/app/com.example-2.apk
After that use aapt:
<sdk_dir>/build-tools/23.0.2/aapt dump badging com.example-2.apk
The output will be something like this:
package: name='com.example' versionCode='1' versionName='1.0.0'
I'm using eclipse to debug my android app which has a c native code.
When i plug in my nexsus4 the ndk external debugging tool works.
when I plug my galaxy note2 it throws the following error when trying to attach to the device:
Android NDK installation path: /Users/eladb/MyWorkspace/android-ndk-r8b
Using specific adb command: /Users/eladb/MyWorkspace/sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using auto-detected project path: .
Found package name: com.myPack
ABIs targetted by application: armeabi
Device API Level: 18
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Using gdb setup init: ./libs/armeabi/gdb.setup
Using toolchain prefix: /Users/eladb/MyWorkspace/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/com.myPack/lib/gdbserver
ERROR: Could not extract package's data directory. Are you sure that
your installed application is debuggable?
I have enabled developers options
and allowed device debugging via usb
it doesn't work for my samsung galaxy note2 (android 4.3) but works for nexsus4 (4.2)
I think this is a known issue?
but how to workarround this?
It's a problem with Android 4.3 in general. Take a look at the Android bug tracker issue 59558 which in turn links to the root of the issue that run-as is borked. (58373) I'm not sure when/if the Note 2 is getting 4.4, so you may want to look into whether or not you can downgrade back to 4.1.2.
This happens due to two known bugs related to the run-as tool. The tool needs to read information about your app from the /data/system/packages.list file inside your Android device. In the case of the first bug, the tool is actually only reading the first 8KB of the file. Thus, if the line containing your app description is below the first 8 KB, run-as will fail. The second bug affects some 4.2.2 and 4.3 Android images by falsely restricting read rights of the packages.list file that contains all the package names.
Solution here: http://visualgdb.com/KB/?ProblemID=nopkg
In my case, I had rooted my Android 2.3 device and changed the default shell to be bash, which was causing issues when ndk-gdb tried to run a shell command.
sh-3.2$ ls -l /system/bin/sh*
lrwxrwxrwx root root 2014-02-01 10:26 sh -> bash
-rwsr-xr-x root shell 82840 2011-09-30 18:55 sh0
sh-3.2$
This was causing the android r9 ndk-gdb script to abort with that 'Could not extract package data directory..' error.
Make a backup copy of your ndk-gdb script first.
Then, near line 615 of ndk-gdb, make the following edits:
# Find the <dataDir> of the package on the device
# on my rooted Android 2.3 device, the default sh has actually been renamed to sh0
# so try that first.
adb_var_shell2 DATA_DIR run-as $PACKAGE_NAME /system/bin/sh0 -c pwd # <-- insert this line
if [ $? != 0 ] # <-- insert this line
then # <-- insert this line
adb_var_shell2 DATA_DIR run-as $PACKAGE_NAME /system/bin/sh -c pwd
if [ $? != 0 -o -z "$DATA_DIR" ] ; then
echo "ERROR: Could not extract package's data directory. Are you sure that"
echo " your installed application is debuggable?"
exit 1
fi
fi # <-- insert this line
Basically, it will try to use /system/bin/sh0 first. If the file doesn't exist, then it will then try /system/bin/sh. I've only tested the /system/bin/sh0 case so far, so YMMV..
I am using vs-android for building native C++ Android applications. I would like to debug from the command line by launching gdbserver on the emulator and connecting to that GDB server. Since I'm not using the Android build scripts I don't get the gdbserver delivered by default. So I added gdbserver to the lib folder from where vs-android collects it and pushes it into the APK. The file is now found on the emulator in the lib folder of the application where my SO is also located when I deploy the application with adb install.
I now try to run gdbserver with run-as but I get the error "Cannot attach to process 924: Operation not permitted (1)".
According to this http://ian-ni-lewis.blogspot.com/2011/05/ndk-debugging-without-root-access.html the server should be able to attach to the process when gdbserver is started with run-as.
Any ideas as to what I could still be doing wrong?
adb shell
su -c setenforce 0
it will solve the problem
To figure out if the problem is with run-as or with gdbserver, try using run-as to execute 'ps' instead of gdbserver, and then see if the 'ps' process is listed as having the same userid as the application's process. If not, you have a problem with run-as. If it is the same userid as the app, then the problem is more likely with gdbserver.
I would like to perform debug operations on the Android open source platform.
I am trying to run "gdbserver :5039 --attach" in my terminal but I keep receiving "command not found".
I have built the Android OS using the "full_crespo-userdebug" configuration, which according to the android docs, should provide me with root access on my Nexus S phone?
How can I set things up so that I can debug?
You can copy it from "$NDK_HOME/prebuild/$PLATFORM/gdbserver/gdbserver"
then use adb to push it to device and make it executable
To debug an android device you first need to run gdbserver on the device.
gdbserver :5039 --attach pid
then in your gingerbread source folder you need to run
source build/envsetup.sh
this will allow you to now run
gdbclient
which should connect to the gdbserver on device
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
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
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
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.
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
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.
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.
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.