I am trying to build a app that after it is installed, will drop another binary that I will execute from within the app. It is basically the command ifconfig but my own version that has some other additions.
Ideally when the single APK file is moved to the device and installed, I would like for the ifconfig file to be dropped in the apps local folder where it will then be used with ProcessBuilder to execute.
Is this something that can be done with Android? The other option would be to download the file but I prefer to have it included with the APK.
You can't quite get that, but you can get the same effect. You can put the file in as an asset, and write the file to the filesystem on first boot of your application. Just check if its already on the filesystem, and if not read it in from assets and write it to the filesystem.
I do question why you're going this route though. Why are you using a C binary rather than writing it in Java/Kotlin? Or using a C library linked via the NDK? Running it via ProcessBuilder is a definite code smell.
Related
As title says, I need to extract files from .rar file and save it on device storage. There are third party tools which supports this. But I was wondering is there any adb /appium /android utility command which provides this functionality ?
There's no way to do this without using a third party tool or app. See the Android Developer reference for ADB.
If use of third party tools is not out of the question for you (you refer to Appium, after all), and you just want to be able to extract the .rar file from the command line, you might try installing an app which can extract .rar files (there are many) and access the correct activity from the command line using the activity manager. You can view the activities available to you for a given APK using the Android Asset Packaging Tool and this command:
aapt dump xmltree <path to APK> AndroidManifest.xml
I would install busybox on your device. This will give you all the commands needed to allow for unzipping the files on your phone. Just disable auto update if you are worried about the application updating.
I have C Linux based application and now I want to port it to Android.
I figured out, that I can extract the toolchain from Android NDK and build my application, but how to make the APK such that I can install it on the android devices without the need of root access.
In Linux, I used to install it using a bash script which used to put my application related files in different folders like /opt, /etc (files shared with other applications) and /var . How can we handle this in Android. Is there a folder similar to /etc in Android where I can put files that other applications can read.
Thanks
-M
First of all, you are lucky if your project compiles "as is" with NDK standalone toolchain. Often, bionic is not enough, and people need to tweak the build environment (from libpthread to full-blown buildroot alternate toolchain with static C runtime).
As for the shared files location, on Android it's named "external storage". Your app and other app may require special permissions to write and read to this location. Directory /opt does not exist here. You don't have write access to /etc, but files like /etc/hosts are available for read.
Regarding the APK. You are right, this is the ultimate way to distribute and install apps on Android. But you can, even without root, to locally install and run a command-line executable. Usually it's done with Developers Options turned on, and enabled USB debugging. Now you can open an adb shell, install and run your program. The trick is that external storage (see above) is marked as 'non-executable'. Therefore, you must find another place for your binary. Usually, /data/local/tmp will be a good choice.
Instead of adb, you can use a terminal emulator on the device.
If you choose to build an APK, you will probably prefer to convert your app to shared library that will perform actions for Java via JNI. But it is also possible to package your command-line binary as part of the APK and use Java Runtime.exec().
I need a list of all the files stored in a given APK file. I am using the NDK.
Challenges:
Get the path to the .APK file on the device.
Iterate through all of the files, recursing through the subdirectories.
You should be able to treat the apk file as if they are zip files.
Since you're working within NDK, you can try using a C++ library like 7-zip to help you browse through the zip file entries.
For the first part of your question, the path to the .apk on the device, refer to this question (it's on StackOverflow, so I won't bother recopying it).
For the second part your question, unzipping an .apk file on the device, download the source for Terminal IDE (Terminal IDE also works on non-rooted devices). Download its source from the download tab, not the browse source tab (which for some reason doesn't work right now).
It's a huge project mostly in Java (it's not exactly the language you're looking for), but it's well organized and remarkably readable.
I want to run tcpdump on the NDK using Process.start() and want to capture this output to a buffer.Can anybody show me how i can do this?Also is the process created in the same Dalvik Vm as the JNI call or is it in a different VM?
Running native processes is not really a supported use of the ndk, but you wouldn't be the first person to do it.
Also note that tcpdump may need to be run as root or setuid root to be useful. And you do have a version of tcpdump compiled and linked appropriately for android?
I think that you actually want android.os.Exec.createSubprocess which is um, not public, rather than Process.start. There's a right way to do it using reflection, and a wrong way to do it by copying the Exec.java (which has declarations of the native methods) into your project. You can use a pipe to recover the results, or you can launch it through the shell and redirect the output to a file which you read from java.
See the source of an android terminal emulator with a local shell option for an example of how to do it.
(Actually, I should restate this - the right way to do it is to duplicate the native functionality of the non-public Exec methods in your own jni lib, so that you are immune to changes in that non-public part of the platform).
I am trying to produce a java front end, via some sort of Android "view" that will allow me to show the console output from a native C/C++ application binary.
I followed the steps from various google searches and I have a tool chain that produces native binarys that I can then "adb push" onto the android device. I can either use the adb shell or a console application like ConnectBot to native to the pushed path and run the binary like so: ./someApplication.
However as I stated in my opening sentence I would like to wrap this binary with a font end producing an apk that can be loaded onto the phone and when it runs it opens up and directs the stdio output from the native binary to the screen.
1) Create android Java project.
2) Place the your library in lib/armeabi folder of the project
3) In your java code loads the library and call exposed JNI calls
An example: http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-methods-bridging-cc-and-java/