Can't run a Java Android program with Valgrind
You have to create a script, lets call it start_valgrind.sh
#!/system/bin/sh
PACKAGE="com.example.hellojni"
# Callgrind tool
#VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=callgrind --callgrind-out-file=/sdcard/callgrind.out.%p'
# Memcheck tool
VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=memcheck --leak-check=full --show-reachable=yes'
export TMPDIR=/data/data/$PACKAGE
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
that should be copied to the device.
Once you have the above script in the start_valgrind.sh file somewhere on your local filesystem you can just use the below script (lets call it bootstrap_valgrind.sh) to do the all the work (copies the start_valgrind.sh script to the phone, runs it, starts your app through Valgrind).
#!/usr/bin/env bash
PACKAGE="com.example.hellojni"
adb push start_valgrind.sh /data/local/
adb shell chmod 777 /data/local/start_valgrind.sh
adb root
adb shell setprop wrap.$PACKAGE "logwrapper /data/local/start_valgrind.sh"
echo "wrap.$PACKAGE: $(adb shell getprop wrap.$PACKAGE)"
adb shell am force-stop $PACKAGE
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
adb logcat -c
adb logcat
exit 0
WARNING: Make sure the property name set with setprop i.e. (wrap.com.yourcompany.yourapp) has a length of less than 31 characters.
Otherwise, you'll get the error "could not set property" because you CANNOT set a property name with a length greater than 31, which is the number maximum allowed characters in the property name.
Also the property value should be <= 91 characters: https://stackoverflow.com/a/5068818/313113
For how to build Valgrind for Android (ARM) see my script from here: https://stackoverflow.com/a/19255251/313113
How to start an android app with valgrind
You can try to clear the logcat first
prompt# adb logcat -c
prompt# adb logcat
You should be able to see the logs coming in once you triggered your application.
am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni
I had problems with my shell script and i used this instead.
adb shell setprop wrap.com.example.hellojni "logwrapper /data/local/Inst/bin/valgrind"
You should be able to pass in the parameter right after valgrind
How do I run valgrind with an Android app?
You get the error "could not set property" because you CANNOT set a property name with a length greater than 31, which is the number maximum allowed characters in the property name: https://stackoverflow.com/a/5068818/313113
Try to reduce the package name length to less than or equal 31 characters when you set the property with adb shell setprop.
And use a bash script to simply things.
For further details see my answer here: https://stackoverflow.com/a/19235439/313113
Related Topics
Android: Programmatically Detect If Device Has Hardware Menu Button
Android: Implementing Progressbar and "Loading..." for Endless List Like Android Market
How to Build an Android Library with Android Studio and Gradle
Toolbar and Contextual Actionbar with Appcompat-V7
Best Practice for Nested Fragments in Android 4.0, 4.1 (<4.2) Without Using the Support Library
How to Downgrade Android Emulator
Parse JSON Array Without Key in Android
Android Java.Lang.Noclassdeffounderror
How to Create a Custom Notification Layout in Android
Googlesignatureverifier Signature Not Valid Message (Google Play Services 9.0.0)
Proguard Causing Runtimeexception (Unmarshalling Unknown Type Code) in Parcelable Class
Changing Overflow Icon in the Action Bar
Android: What Is Android.R.Id.Content Used For
How to Open an Android Studio Project in Eclipse
How to List Files in an Android Directory