0

I need to build a command-line tool that I can run in an Android shell.

This question is not about how to build using command-line tools, which is pretty much all I find when I search SO/google for this question.

What I can do: Write a simple Java jar that runs from app_process

What I want: A tool that uses Android libraries (such as the packagemanager) that runs from the command line (such as an 'adb shell') and then exits - so not an App, doesn't have a view and isn't really following the Android life-cycle.

So presumably I either need to figure out how to build such a tool either from an IDE (such as Android Studio) or else from the command-line using the Android libraries.

Someone gave the (mostly) reasonably suggestion that I just look at how 'pm' is compiled, though I can't figure out how to do that without downloading the entire Android source and doing a full build (and I don't really have the time or HD space for that).

So I suppose another solution would be if someone could just telling me how to compile 'pm' since I could repurpose that for my needs.

  • This is a more generalized question from what I originally asked here: http://stackoverflow.com/questions/30764318/how-to-call-getpackagemanager-from-android-command-line-executable – David Ljung Madison Stellar Jun 19 '15 at 20:11
  • I am not aware that what you want is possible, outside of a custom ROM/full firmware build. For example, `pm` is built as part of a full firmware build, as it is compiled against Android internal classes (all the `com.android.internal` and `libcore` stuff). – CommonsWare Jun 19 '15 at 20:22
  • Interesting - does 'pm' really use a different set of libraries than a normal app? That seems strange, considering that the functionality is essentially the same. – David Ljung Madison Stellar Jun 20 '15 at 23:57
  • "crashed WITHOUT accessing onSuccess, onError Functions! and I have this in my logcat" -- you are welcome to look at [the Java source code to `pm`](https://android.googlesource.com/platform/frameworks/base/+/master/cmds/pm/src/com/android/commands/pm/Pm.java), and you will see it refer to lots of things that are not in the Android SDK. "That seems strange, considering that the functionality is essentially the same" -- `pm` can do many things that Android SDK apps cannot, through a combination of running as superuser via `adb shell` and having lower-level access to Android's internals. – CommonsWare Jun 21 '15 at 11:11
  • "I'm confused what your first quote "crashed without..." is referring to" -- whoops! Sorry, cut-and-paste error there. – CommonsWare Jun 22 '15 at 12:06
  • I know pm can do more, but it seems the functionality I need is available in the normal Android libraries since I can easily write an App with a view that will list packages – David Ljung Madison Stellar Jun 22 '15 at 13:54

0 Answers0