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

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.

Related

Run XSLT-script on android smartphone and/or tablet

I have a relatively simple question:
Is there a possibility to run an xslt-script on an android device? I have an .xml file, using a .xsl script to create a new .xml file.
On windows I am using saxon, which works good, but as I don´t have always access to it I would prefer to run a script on my android phone and/or android tablet.
I did some research with google and also on this site, but i didn´t found any clear answer.
thanks in advance and greetings
I have now found a way to run both Saxon-JS 2 or rather its command line tool xslt3 as well as Saxon HE Java from a command line terminal for Android.
I installed Termux, I had to use the version from F-Droid, as the one on the Google play store seems to be no longer supported, then in the Termux terminal shell I installed node and java (try to run with e.g. ˋnodeˋ and it will tell you the ˋpkg install ...ˋ command line to install, then I did e.g. ˋnpm install -g xslt3ˋ to install Saxon-JS's command line tool and downloaded the Saxon HE 11.2 Java zip from Sourceforge with wget and unzipped it and finally I am able to run e.g. xslt3 to run Saxon-JS or java -jar path-to-saxon11jar to run XSLT 3 (or in the case of Saxon Java of course XQuery too.
The interaction with the rest of the Android file system is a bit complicated to find out but the Linux Terminal shell has its own file system with a storage folder with sub folders like storage/download linked to the usual download folder other Android apps (e.g. your browser) use.
Here is a screenshot of Termux on my Android tablet showing the execution of Saxon HE 11 Java and Saxon-JS 2: .
It turns out the same procedure doesn't work quite as well on my Android phone which has Android 12 as the running Java and therefore Saxon HE 11 or any other Saxon Java HE currently does not work due to a known issue https://github.com/termux/termux-packages/issues/7332. But Node.js and npm and therefore Saxon-JS with xslt3 run fine on that phone.

Why is attaching gdbserver to a native android app failing?

I am developing a fully native application in using C++ and pure CMake as the build system - no Android Studio involved at all (proof of concept here)
The code builds, apk is generated and can be installed and run via ADB without issue but I cannot get gdbserver64 to attach to the process for debugging.
More details:
App is built against SDK/NDK API level 30
Attempting to debug on an Android 11 emulator instance without Google Play
I can run adb root just fine
Image already includes gdbserver and gdbserver64, attempting to use those
Developer options and USB debugging enebled in emulator
App has android:debuggable="true" in manifest
But every time I try gdbserver64 :5039 --attach $(pidof my.app.id)
I get /bin/sh: <app_pid>: inaccessible or not found
What am I missing? And no, I cannot just move to Android Studio - this is a cross platform project that needs to be buildable using only CMake.
According to my observation, this may be a bug of prebuilt gdbserver. It treats the parameter after --attach as a program name and tries to start it.
It's not really an answer, but in similar configuration to yours I got same error message and unable to overcome this. For me, switching to lldb helped, see e.g.

Running C code on android using termux or gnuroot?

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.

run-as: Could not set capabilities: Operation not permitted

on android 6.0.1 I am getting this error when trying to use run-as.
⋊> ~ adb shell 14:29:01
shell#trlte:/ $ run-as org.ligi.passandroid
run-as: Could not set capabilities: Operation not permitted
I really like the run-as command - is there a way to get it to work on 6.0.1 ?
If you have a SAMSUNG device, don't bother - SAMSUNG broke run-as by dropping the setuid flag (so run-as has no chance of switching to a different identity).
Also don't bother trying the Smart Switch "reinitialize device" workaround, it won't work until SAMSUNG fixes it in the firmware (so it is worth updating to the latest version).
Use some other method to access your app's data, like adb backup:
adb backup -f data.ab <my.package>
dd if=data.ab bs=24 skip=1 | openssl zlib -d > data.tar
Instead of dd you can use the abe tool, which can also write .ab files.
For me, it went like this. I am using Samsung s6 API 24. The error list log's detail was the same as mentioned in the question. But when I checked the Build Logs I found the solution written there. To set the MSBuild. So I followed the following steps to resolve this and the app ran successfully.
To correct this problem I had to
Unload Android Project from solution explorer
Right-Click unloaded project and "Edit Project File"
Searched code for "EmbedAssembliesIntoApk"
Found the occurrence in the project file
<EmbedAssembliesIntoApk>false</EmbedAssembliesIntoApk>
Change it to true and reload the project.
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
Ran the app and the app starts running on Samsung s6
The solution for me was the parameter -autolaunch in the Debugger configuration of the project in the field Parameters.
I use Delphi 10.2 with S7 Edge Android 7
Unlike another answer here, I have also tried to use smart switch & hard device resetting, but unfortunately that approach did not work for me (Wasted extra one hour just to try out that approach). Besides not working, it might create additional problem "samsung account: session expired" - problem, which can be fixed only if you have root access to your device.
I by myself have used instructions from here:
https://www.youtube.com/watch?v=Sy4FWLHxGYs
and then from here:
https://www.tomsguide.com/us/samsung-galaxy-s6-guide,review-2856-3.html
for getting root access to your device, and after that run-as can be executed with additional command "su -c" as for get root user. So whole command will look like this:
su -c run-as org.ligi.passandroid
WARNING: Gaining root access to your device will most probably void your device warranty if you have any left.
Additionally to this, I wanted to be able to debug my application inside Samsung Galaxy S6, so I've altered Visual studio components, more instructions can be found here:
https://issuetracker.google.com/issues/37093233#comment53
If you happen to have Samsung based android device - I have already reported that bug to Samsung, but I've could not get any time schedule if when and if at all they are going to fix this issue. If you own some other Android device - makes sense to report this problem to manufacturer.
I was working from Delphi 10.1 berlin.
I was presented with the same problem and my solution was to configure the sdk to the previous version.
I was using Android SDK 25.2.5.32bit and downgraded to android SDK 24.3.3 32 bit. To configure:
Tools->Environment Options -> SDK Manager
Then, add the necessary sdk, in this case android SDK 24.3.3 32 bit.
#RustyX answer helped my partially. zlib didn't work in my Mac. So I had to use the Android Backup Extractor to convert .ab file to .tar file. You can download it here.
For the full step by step instruction, refer here.
In Visual Studio, App properties, Android Options, changing the debugger from C++ to .Net(Xamarin) seems to have fixed the problem for a mixed C++/C# app.
Also got this error today when I tried to deploy/debug my application on a Samsung Xcover 3 running Android 6.
I solved it by changing the project property "Android Options / Use Fast Deployment" to false.
Here is solution for MS Visual Studio 2022.
https://www.youtube.com/watch?v=_r9GLm0k55o
Just uncheck the "Use Fast Deployment".
I had previously posted an answer here which was deleted, maybe because it was a link to another stackoverflow question referring to the answer I gave there, instead of containing the full answer.
Reposting its contents here from https://stackoverflow.com/a/43242739/7823460:
I had a very similar issue on Samsung Galaxy S6 Edge, trying to start debugging on VS2015, I got a different error, much less verbose than in the attached screenshot:
run-as: Could not set capabilities: Operation not permitted
Based on the contents of the attached screenshot above, I tried 'initializing' / factory resetting the device using Samsung's Smart Switch and it actually fixed the 'run-as' issue I was having.
This is the only solution which worked and didn't involve rooting the device, so I believe it must be publicly available. Of course people attempting this should keep in mind that factory reset means that data will be lost, unless it's backed up. The same Samsung software helps with backing up your data.

Cross Compiling v4l2-ctl for Android

I've got a usb camera working on android (via Android On-The-Go), and I'm looking to change the exposure of the camera. I've been able to get this to work by using v4l2-ctl on a linux machine, and I'm hoping to do the same on my Android device.
The install file mentions the following:
Android Cross Compiling and Installing:
----------------
v4l-utils will only build using the complete AOSP source tree, because of the
stlport dependency.
List of v4l-utils that supply an Android.mk makefile:
* utils/v4l2-compliance
* utils/v4l2-ctl
* utils/v4l2-dbg
To cross compile an utility you must first configure the shell with Android's
envsetup.sh to add the mm alias, before running lunch to select your target
device.
cd /path/to/aosp
source build/envsetup.sh
lunch
cd /path/to/v4l-utils
cd <utility>
mm
So I downloaded the android source, ran the first two commands and lunch successfully. I then cd'd into v4l-utils/v4l2-ctl and ran mm. I got the following error:
make: *** No rule to make target `out/target/product/generic/obj/lib/crtbegin_dynamic.o', needed by `out/target/product/generic/obj/EXECUTABLES/v4l2-ctl_intermediates/LINKED/v4l2-ctl'. Stop.
What can I try to fix this?
Note: Normal compilation works: I can make all of v4l2 with ./bootstrap.sh, ./configure, and then make.
I've figured out how to do it! I found that the instructions worked great, except for these two points:
Download and Build the Entire Android Source
Before doing anything, you need to download and make the full Android source. This means setting up your environment, downloading it, and then building it.
Make sure that you're downloading the correct version of the Android source (that is, the version that's running on your phone).
For a faster download, run repo-sync with -c, for the current branch only
I suggest getting a large hourly billed server and running it on there. The network connection will be better, and the machine is probably better than your own. I got an 8 core, 16GB machine on DigitalOcean.
When running lunch, I just chose the first option: aosp_arm-eng
Set the TOP Variable
When doing the mm step, you'll get an error saying Couldn't locate the top of the tree. Try setting TOP. So run export TOP=/location/of/android/source

Categories

Resources