Running C code on android using termux or gnuroot? - android

I'm trying to run c code on my android device using various terminal emulator apps. I have tried 3 so far and all of them are giving me errors. The first one I tried was the most popular: terminal IDE. Ever since the later versions of android have been released this app will not compile c code due to a position independent executable (PIE) error. Next up was a promising app called termux. This app allows me to compile my C code with gcc but gives me "permission denied" errors whenever I try to run even the simplest of codes. I have examined and researched this error thoroughly. I have tried using chmod in various different ways as well as checking the permissions using ls -l and have tried compiling and running in both the external sd card AS WELL AS on the internal device storage. I understand that the SD card doesn't have exec permission but it still won't work even in my device's internal memory. I have asked for help from the termux creator but to no avail. No matter what I do I cannot seem to get these codes to run on my android device. It is not rooted and I don't plan to root it any time soon. All of these apps claim that they should work without rooting the device. I finally tried running C code in another app (my last hope) called gnuroot. Unfortunately I'm still getting the permission denied error, but the code does compile as it did in termux. I can't access any of the directories created by these apps by the way. They are hidden from the "my files" app which normally lets me browse directories on my device. However, the directories shown when I type in ls are not in the my files app, so I can't place any files directly in them. I can only see the basic home directories for termux and gnuroot, but when I try to place the code in there, I still get the permission denied error. Furthermore, I don't know what directory to even place the code in for it to work. I'm totally lost and really need help. Thanks.

I've gotten C programs running well under termux using gcc.
While compiling, compile your code using the -o option, and no -c, like this:
gcc -o helloworld helloworld.c
The object file helloworld will be created with execute permissions and you can run it with ./helloworld.
Note that the source files must be in the home directory first. If you haven't changed your environment variables, first go to your home directory with cd and then compile your source files there.

In Termux, if you use Midnight Commander or Ranger you can go back one directory from home to files, and in there you'll find the apps /etc, /bin, /usr, /etc.. directories. Maybe that is where you can find or send the files you are looking for.

Try to upgrade Termux. Simply run:
"packages upgrade" (with no quotes)
in command line.
If this don't fix the problem, run:
"packages install termux-exec" (with no quotes)
Hope this help.

Related

Building WebView From Chromium for Android

I am trying to follow the instructions to build the webview apk from chromium base. I am running a Android-7.0 build. I finished the compilation process for chromium and generated the APK. I have two questions related to steps after APK generation.
Firstly the library name is different from what I expected. The default webview.apk has a library name libwebviewchromium.so, but the APK I built from chromium (SystemWebView.apk) contains the lib libwebviewchromium.cr.so. I wanted to ask whether that can cause problems and if others also saw this.
Secondly, I am unable to uninstall the com.android.webview app from the device. The instructions require uninstallation of this app and deleting its folder before the new APK can be installed. I get the error:
$ adb uninstall com.android.webview
[DELETE_FAILED_INTERNAL_ERROR]
I wanted to ask if anyone knows how to resolve this. I saw a related question and want to ask if there is any other approach that doing what this answer suggests.
The following answer is related to the second part of my question.
I did the following steps to make the SystemWebView.apk work (note: the webview.apk was a system app in my build under /system/app; the steps below were used to install & test SystemWebView.apk as a third party app)
(Take a look at step 6 first for taking back up of 2 files)
Firstly I followed the linked answer to adb pull & edit the packages.xml and packages.list files (I haven't pushed them yet)
adb shell stop
I push the two files
I then deleted the following folders (basically any trace of com.android.webview):
/system/app/webview
/data/data/com.android.webview
/data/user/0/com.android.webview
/data/misc/profiles/cur/0/com.android.webview
/data/misc/profiles/ref/com.android.webview
/data/user_de/0/com.android.webview
adb install SystemWebView.apk
I also had kept a back up of libwebviewchromium64.relro and libwebviewchromium32.relro files from /data/misc/shared_relro/. After the install, I noticed that these files get erased for some reason, so I copied them in again (first copying into sdcard and then moving into shared_relro folder).
adb shell start
After that I tested a simple app containing a WebView, and could see web pages loaded.
You have to build SystemWebView.apk with
ninja -C out/Release system_webview_apk
For more details check this page.
https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md
and
https://www.chromium.org/developers/how-tos/build-instructions-android-webview
adb uninstall com.android.webview
fails because this is a system app, you can directly replace the webview.apk in
/system/app/webview/ dir, after this do stop && start
for this you need root permission.
Native web view has many limitations in performance and caching.
I would rather suggest you to CustomTabsClient, a web view supported by Chrome Browser. you could get it by adding following dependencies to your project.
dependencies {
...
compile 'com.android.support:customtabs:23.3.0'
}
For more detail visit.
https://developer.chrome.com/multidevice/android/customtabs

sl4a permission issue after android upgrade

I installed Sl4A via this link : https://electrum.org/android.html
I wanted to run electrum on my Nexus 10.
installation went fine, electrum was working (send & receiving btc).
Then, I upgraded to Android 5 (last version, lolipop I think).
After that, I can't run any Python script via SL4A.
I checked logcat file, I saw some lines about permission & chmod, but not sure if it's related.
I just rolled to 4.4.4 and am having the same issue.
I dug into the error a bit more: seems the new "Sandbox of Safety" functionality on Android that is supposed to keep rogue apps from writing to directories they're not supposed to write to is preventing SL4A from writing to directories it probably should be able to write to - ie, SD card and such
I moved the files I was writing to to the SL4A directory on internal storage and my script worked again.
I would really like to see a better solution though

How do I run an Android app I've written in Red?

When I enter this in the Windows CMD...
red -c -t Android hello.red
...Red outputs a file called hello with no filename extension. If I transfer this file to my Android device, it doesn't know what to do with it.
What additional steps must I follow to test my Red code on my Android device?
Which of those steps, if any, must I do differently, depending on whether or not my code will attempt to use the Android bridge?
The Android port is a work in progress done in the android branch. In that branch, using:
red -t Android <script.red>
will use the APK backend for the new packaging layer that will handle the whole process of APK generation for you (provided that you have a JDK1.6+ pre-installed). If all went well, you will get an APK in your working folder.
In case you need to debug the building process, you need to edit the system/formats/APK.r file and set on line 11 the verbose word to yes.
Note: We are working on removing all the external dependencies one by one.
EDIT: The Android Red port has been moved to a private branch and actively worked on. It will be made public once beta stage is reached.
Unless you package up the executable into an .APK, then for security reasons Android throws up some walls in your path to chmod +x it and run.
I followed these directions, just with:
$ cd /data/data/jackpal.androidterm/shared_prefs
$ cat /sdcard/Download/hello.bin > hello
$ chmod 755 ./hello
$ ./hello
Without rooting or otherwise, you wind up with that weirdness like using cat instead of cp, and slipping the file into a strange directory where execution is allowed.
Tested on Nexus 5.
I've not tried yet, but check this: http://www.red-lang.org/2011/12/arm-support-released.html
Also you may know, that there is an experimental Android version here: https://github.com/red/red/tree/android
It appears the question has been answered, but for those who want more, there is an article for getting started with Red for Linux and Android in the March 2014 issue of ODROID Magazine at http://magazine.odroid.com .
There is also going to be a short how-to article in the July 2014 edition (released in the next few days) by Gregory Pecheret that will demonstrate building an .apk from scratch in Red.

How do I install APK using Android updater script

I'm attempting to use Android's updater script language (Edify?) to install an APK over-the-air to an embedded device that I have control over. Here's a link that describes the language.
My first attempt was the following:
package_extract_file("added_files/data/app/test.apk", "/data/app/test.apk");
That resulted in test.apk being automatically installed in /data/data/com.acme.test, however the directory /data/data/com.acme.test/lib is empty, whereas it should contain test.so, a shared library contained in test.apk. (If I manually install using adb install test.apk, the library is extracted.)
I then tried extracting the APK into /data instead of /data/app so the OS wouldn't automatically install it into /data/data, and I could try installing using the script:
package_extract_file("added_files/data/app/test.apk", "/data/test.apk");
run_program("/system/bin/pm", "install", "/data/test.apk");
That resulted in the following error:
about to run program [/system/bin/pm] with 3 args
run_program: execv failed: Exec format error
run_program: child exited with status 1
I'm not sure why the above error happened.
Is there a way to install an APK and have its shared libraries extracted automatically? I could install the libraries manually, but I'm hoping to avoid that.
I'm not familiar with Edify, but by looking at the documentation, package_extract_file() simply extracts the APK as the archive file that it is. Why data ends up inside /data/data is strange; are you sure that isn't just left behind from a previous installation? I'd suggest fully uninstalling the app and trying again.
It seems to me that that particular function isn't suited for installing the app. You might want to try installing it through a command:
run_program("adb", "install", "-r", "added_files/data/app/test.apk");
Edify scripts run in a recovery mode and depending on your device not all partitions are available by default. Most likely your problem is that the partition you are trying to use is not mounted yet.

Compiling on an ARM Emulator for use on an Android Phone

so I'm trying to compile a program on an ARM emulator (Quem and the laungauge is C) for use on an Android phone. This is because I can't get build-essentials and/or cmake on my android phone, but I do have Terminal Emulator and Busybox.
Anyways, I compiled the program last night (Took forever!) and when I tried to run it on Android today It was originally saying Permission Denied (Even though I have SU), I found out that it was because I need to have it as executable, but since the sdcard was a FAT32, I wasn't able to use chmod. So I mounted /system, and copied over the binary to there after chmod 777'ing it. And now it gives me ./myprogram: not found even though it is clearly there.
Doing some reading, people are saying it could mean there are missing libraries, but Android doesn't have the ldd command so I don't know how to find out what it's missing. Also, might be a game breaker, but I found out that my phone is on an ARMv7 where as the emulator is ARM926EJ-S will this make a difference?
Any input is great!
I makes little sense (IMHO) to compile on the emulator. It makes more sense to use a cross compiler to build your application and its dependencies. Please search for info on using the NDK.

Categories

Resources