Lazarus

Programming => Operating Systems => Android-JVM => Topic started by: regressist on October 27, 2021, 02:18:35 pm

Title: Compile to a tablet?
Post by: regressist on October 27, 2021, 02:18:35 pm
Hi all,
I am sorry if my question is stupid and probably very wrong. My experience with Pascal is limited to programs like the ones in the very old Jensen, Wirth- Pascal User manual and report- 1978 (Yes, 78!), no graphics, no class, no make, etc. Sometimes I revamp it when I need to solve some problems which are too complex for some math packages.
I have successfully written a small program which makes some computations with integers, does not need any input or interactions, and has very little requirements in terms of ram, etc. During execution it writes on screen some numbers to show the status of the computation, at the end it just writes to a file some numbers. It runs on pc, BUT the problem is the CPU usage, if I want to find some solutions I need weeks and probably months. I do  not want to burn my PC. In absence for now of access to a powerful workstation or a mainframe I was thinking to use an old Samsung Galaxy tab, even though slower I would not care if it would die.
So the question is: is there any possibility to compile this program (it is only a basic program) to an .apk which in my dreams would need only to be tapped and starts the computation, again no interaction.
Please note that as an add-on I know nothing also of Android.
Thanks in advance to anybody will take the time to answer

Sergio
Title: Re: Compile to a tablet?
Post by: af0815 on October 27, 2021, 02:46:14 pm
It is not the easiest way. Normally nothing for a newbee

Docs for installing are here https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/docs in LAMW_Getting_Started.txt

Search for LAMW + Lazarus give more results.

BTW: A RasPi will also a cheap soloution - can run headless
Title: Re: Compile to a tablet?
Post by: marcov on October 27, 2021, 02:48:18 pm

BTW: A RasPi will also a cheap soloution - can run headless

Or any PC out of a dumpster will probably be both easier and faster.
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 27, 2021, 03:45:11 pm

BTW: A RasPi will also a cheap soloution - can run headless

Or any PC out of a dumpster will probably be both easier and faster.

Do any "cloud-based" computation services have off-peak rates? In any event, reading between the OP lines if this really is going to need lots of CPU time the first thing to do is to work out to what extent it can be split into threads (since just about every CPU now has multiple cores) or can be parallelised over a cluster (or real computers or VMs provided by AWS or whoever).

MarkMLl
Title: Re: Compile to a tablet?
Post by: alpine on October 27, 2021, 04:07:49 pm
Although it is not "Compile" to a tablet, searching a time ago for a Pascal app for purely educational purposes, I found Pascal N-IDE (https://play.google.com/store/apps/details?id=com.duy.pascal.compiler&hl=en_US&gl=US). It is an interpreter and it can load/save scripts to the phone storage, so it is possible to transfer scripts from/to PC.

Đ•valuated by me for nothing but for weird tests how it handles enumeration types, multi-dim arrays and things like that. It doesn't work well.

Very simple to use but probably it is completely worthless for computational intensive tasks. Not tested though.
Title: Re: Compile to a tablet?
Post by: engkin on October 27, 2021, 05:30:03 pm
Hi all,
I am sorry if my question is stupid and probably very wrong. My experience with Pascal is limited to programs like the ones in the very old Jensen, Wirth- Pascal User manual and report- 1978 (Yes, 78!), no graphics, no class, no make, etc. Sometimes I revamp it when I need to solve some problems which are too complex for some math packages.
I have successfully written a small program which makes some computations with integers, does not need any input or interactions, and has very little requirements in terms of ram, etc. During execution it writes on screen some numbers to show the status of the computation, at the end it just writes to a file some numbers. It runs on pc, BUT the problem is the CPU usage, if I want to find some solutions I need weeks and probably months. I do  not want to burn my PC. In absence for now of access to a powerful workstation or a mainframe I was thinking to use an old Samsung Galaxy tab, even though slower I would not care if it would die.
So the question is: is there any possibility to compile this program (it is only a basic program) to an .apk which in my dreams would need only to be tapped and starts the computation, again no interaction.
Please note that as an add-on I know nothing also of Android.
Thanks in advance to anybody will take the time to answer

Sergio

Hi Sergio,

Are you using Linux or Windows?
Which Galaxy tab do you have? Is it rooted?

Since you are not using any graphical interface, you don't need an apk file. Android includes a terminal. What you need is a cross compiler on your PC and a terminal emulator on your Galaxy. You program as usual on your computer, and when you think your code is ready you cross compile it to produce a version that works on your Galaxy.

Transfer that version to your tablet and run it. This step is a little tricky if you are not familiar with Linux and what you do depends on the Galaxy being rooted or not. In the most common situation,  you copy the program to a specific folder, change its mode to executable, and run it.
Title: Re: Compile to a tablet?
Post by: regressist on October 27, 2021, 08:30:17 pm

Hi Sergio,

Are you using Linux or Windows?
Which Galaxy tab do you have? Is it rooted?

Since you are not using any graphical interface, you don't need an apk file. Android includes a terminal. What you need is a cross compiler on your PC and a terminal emulator on your Galaxy. You program as usual on your computer, and when you think your code is ready you cross compile it to produce a version that works on your Galaxy.

Transfer that version to your tablet and run it. This step is a little tricky if you are not familiar with Linux and what you do depends on the Galaxy being rooted or not. In the most common situation,  you copy the program to a specific folder, change its mode to executable, and run it.

Hi and thank you for your reply, also to the others. I am using Windows, I do not know Linux, and the Galaxy is rooted, even though I did it blindly 3 years ago to install version 7 of Android, which now works quite bad, the whole process was a bit disappointing, poor outcome.
The first question would be which cross compiler is available? And the second is the hardest I guess, how can I run the terminal emulator? I remember vaguely that I was able to enter into a tool, TWRP ...
Title: Re: Compile to a tablet?
Post by: ojz0r on October 27, 2021, 08:48:36 pm
I have the FPC compiler installed in Termux on my android phone.
This is where i usually do all my (hobby) coding and then compile and run them in the Termux terminal, so no "native" apk.
Title: Re: Compile to a tablet?
Post by: engkin on October 27, 2021, 09:06:36 pm
The first question would be which cross compiler is available?

On Windows I used to used Laz4android (https://sourceforge.net/projects/laz4android/).
What version of Windows are you using?
What model number is your Galaxy?

And the second is the hardest I guess, how can I run the terminal emulator? I remember vaguely that I was able to enter into a tool, TWRP ...

For terminal emulator I used to use this one (https://play.google.com/store/apps/details?id=jackpal.androidterm)

For your purpose, the first difference between Windows command line and Android terminal is permission to run an app. The executable on Windows has exe extension, while on Linux it has no extension. If you copy an executable from your PC to Android you need to change its mode to make it executable using chmod:

chmod 755 ./yourFileName

I used to put my test files in /data/local/tmp/ folder, then change their mode, and run them

Unlike Windows, in Android/Linux terminal to run an executable located in the current directory you need to add a period and a slash ./ before the executable:
./test


I forgot to mention, if you have the drivers for your Galaxy installed on your Windows, you can use ADB (Android Debug Bridge) on your Windows to copy files, change their mode, and run them from within WIndows itself. Also, you can use an open source application called scrcpy to see your Galaxy on your Windows screen. ADB and scrcpy should help while working on your app if you prefer to use one screen/keyboard/mouse instead of switching back and forth between the two devices.

Title: Re: Compile to a tablet?
Post by: regressist on October 27, 2021, 09:54:17 pm

On Windows I used to used Laz4android (https://sourceforge.net/projects/laz4android/).
What version of Windows are you using?
What model number is your Galaxy?

For terminal emulator I used to use this one (https://play.google.com/store/apps/details?id=jackpal.androidterm)

For your purpose, the first difference between Windows command line and Android terminal is permission to run an app. The executable on Windows has exe extension, while on Linux it has no extension. If you copy an executable from your PC to Android you need to change its mode to make it executable using chmod:

chmod 755 ./yourFileName

I used to put my test files in /data/local/tmp/ folder, then change their mode, and run them

Unlike Windows, in Android/Linux terminal to run an executable located in the current directory you need to add a period and a slash ./ before the executable:
./test

I forgot to mention, if you have the drivers for your Galaxy installed on your Windows, you can use ADB (Android Debug Bridge) on your Windows to copy files, change their mode, and run them from within WIndows itself. Also, you can use an open source application called scrcpy to see your Galaxy on your Windows screen. ADB and scrcpy should help while working on your app if you prefer to use one screen/keyboard/mouse instead of switching back and forth between the two devices.

The Galaxy is 10.1, I am using a virtual machine XP (VMWare) for Lazarus to avoid cluttering the PC.
I appreciate a lot the time you are wasting to answer to me, but I have to say that it's unlikely I will succeed, I know practically nothing of what you are saying and do not know where to start!! I will try of course, I like too much your solution...
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 27, 2021, 10:03:03 pm
OP: You might find https://hackaday.com/2020/10/07/linux-fu-the-linux-android-convergence/#more-429444 worth reading.

MarkMLl
Title: Re: Compile to a tablet?
Post by: engkin on October 27, 2021, 11:52:04 pm
I know practically nothing of what you are saying and do not know where to start!! I will try of course, I like too much your solution...

I would suggest you start with laz4android and see if it works on Windows xp.

You only need to be patient and when you get stuck don't hesitate to post your questions. The forums are full of friendly people.
Title: Re: Compile to a tablet?
Post by: alpine on October 28, 2021, 12:24:32 am
I have the FPC compiler installed in Termux on my android phone.
This is where i usually do all my (hobby) coding and then compile and run them in the Termux terminal, so no "native" apk.
That's the beauty of the forum life!

Installed the Termux from the app store, then: Settings->Applications->Termux->Permissions, enabled the Storage permission.
In the Termux console:
Code: [Select]
$ pkg install clang
$ pkg install fp-compiler
$ termux-setup-storage
the last one creates a new directory in termux, ~/storage, which contains simlinks to /storage/emulated/0 and can be accessed by a standard gui file manager.

Wrote 1.pas with nano (text editor):
Code: Pascal  [Select][+][-]
  1. begin
  2.   writeln('hello!');
  3. end.

And then:
Code: [Select]
$ fpc 1.pas
$ ./1
hello!
Just simple as that! It is just Bluetooth keyboard missing.

Thanks ojz0r!
Title: Re: Compile to a tablet?
Post by: regressist on October 28, 2021, 10:44:42 am

I would suggest you start with laz4android and see if it works on Windows xp.

You only need to be patient and when you get stuck don't hesitate to post your questions. The forums are full of friendly people.
[/quote]

Thank you, yes it works, it's like the lazarus-2.0.12-fpc-3.2.0-win32 with which I compiled my program. But the result is the same, just an  *.exe, I thought it would come out with a linux/android executable. I did not find any menu to have an android output (surely I'm wrong on this)

S
Title: Re: Compile to a tablet?
Post by: engkin on October 28, 2021, 12:25:17 pm
Thank you, yes it works, it's like the lazarus-2.0.12-fpc-3.2.0-win32 with which I compiled my program. But the result is the same, just an  *.exe, I thought it would come out with a linux/android executable. I did not find any menu to have an android output (surely I'm wrong on this)

Yes, by default, it gives an exe file. You can change that by changing the target OS to Android, and target CPU to Arm. Both are in the Project Options window. You can open this window from the main menu under Project, or using CTRL+Shift+F11 key shortcut if I recall correctly.

I am not by a computer now, I'll try to post a screenshot later if you did not find them.
Title: Re: Compile to a tablet?
Post by: regressist on October 28, 2021, 04:12:26 pm
Yes, by default, it gives an exe file. You can change that by changing the target OS to Android, and target CPU to Arm. Both are in the Project Options window. You can open this window from the main menu under Project, or using CTRL+Shift+F11 key shortcut if I recall correctly.

I am not by a computer now, I'll try to post a screenshot later if you did not find them.
Done (thanks). Surprisingly upon compilation I get an error on the 2nd last line [error while linking]

    writeln(namefile,'Total solutions: ' , Nsoluzioni);

I am just writing in namefile:  Total solutions   nnn
And an identical command is written before, without any problem.

namefile is output.txt

In the meantime I also installed on the Galaxy your suggested Terminal emulator. It seems to work but touch wood because the OS is not performing well in general, it was probably a mistake to switch to this non-native OS.

Note: when you are fed up of supporting just say that, I do not want to disturb you too much!
Title: Re: Compile to a tablet?
Post by: engkin on October 28, 2021, 08:50:45 pm
Done (thanks). Surprisingly upon compilation I get an error on the 2nd last line [error while linking]

    writeln(namefile,'Total solutions: ' , Nsoluzioni);

I am just writing in namefile:  Total solutions   nnn
And an identical command is written before, without any problem.

namefile is output.txt

I think the location is irrelevant here, because the compiler did not issue the error. It is the linker. Probably you need to check other messages before or after this one.

To make sure you have a working environment, start a new project of type Program and only add writeln to the template Lazarus produced:
Code: Pascal  [Select][+][-]
  1. ....
  2. begin
  3.   Writeln('Hello World!');
  4. end.

Change the target OS to Android, CPU to Arm, and Target processor to ARMV7A

If you try to compile, you'll see a similar error. When you check the messages, the linker was unable to find one of the files, named: crtbegin_dynamic.o. This file comes with Android NDK. There are a few copies for each Android API version depending on the target processor.

To save you from needing to install the NDK, I'll make a guess and attach a zip file with the needed files. Expand the compressed file and point the test project to it using:

Compiler Options - Paths - Libraries

In the meantime I also installed on the Galaxy your suggested Terminal emulator. It seems to work but touch wood because the OS is not performing well in general, it was probably a mistake to switch to this non-native OS.

Great.

Note: when you are fed up of supporting just say that, I do not want to disturb you too much!

Don't worry about it.
Title: Re: Compile to a tablet?
Post by: alpine on October 28, 2021, 09:13:14 pm
@engkin, @regressist
Wouldn't it be much simpler just by installing Termux+clang+fp-compiler on the tablet?

No need for Android NDK, laz4android, etc. Just a text editor on the PC and USB cable to transfer the source files to the device.
Title: Re: Compile to a tablet?
Post by: engkin on October 28, 2021, 09:47:23 pm
@engkin, @regressist
Wouldn't it be much simpler just by installing Termux+clang+fp-compiler on the tablet?

No need for Android NDK, laz4android, etc. Just a text editor on the PC and USB cable to transfer the source files to the device.

I don't think either way is simpler. If you are comfortable using Linux or fpc directly you might prefer using Termux. If you are a Windows person or used to Lazarus, then you might prefer Laz4android.

In both cases you have to set the environment up.
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 28, 2021, 10:53:11 pm
It seems to work but touch wood because the OS is not performing well in general, it was probably a mistake to switch to this non-native OS.

I'm unaccountably disturbed by that: what do you mean by "non-native" in this context?

MarkMLl
Title: Re: Compile to a tablet?
Post by: alpine on October 28, 2021, 11:10:00 pm
@engkin, @regressist
Wouldn't it be much simpler just by installing Termux+clang+fp-compiler on the tablet?

No need for Android NDK, laz4android, etc. Just a text editor on the PC and USB cable to transfer the source files to the device.

I don't think either way is simpler. If you are comfortable using Linux or fpc directly you might prefer using Termux. If you are a Windows person or used to Lazarus, then you might prefer Laz4android.

In both cases you have to set the environment up.
Exactly what I'm writing about ... I've installed Termux+clang+fpc in a matter of minutes. Making my first apk with laz4android, LAMW, Android SDK+NDK took me days and several gigs on my HD. And then we should introduce OP to the Android bridges et al. Much, much steeper IMHO.
Title: Re: Compile to a tablet?
Post by: engkin on October 28, 2021, 11:24:26 pm
No, no APK, just an executable for the terminal. But wait, did you produce an APK using Termux?
Title: Re: Compile to a tablet?
Post by: ojz0r on October 29, 2021, 09:08:38 am
No Termux only compiles like on any Linux system, run it with ./application-name.

However there is the app Tasker where you can reach into Termux to execute commands or in this case an executable. The same developer also has an app called "Tasker App Factory" that can convert a Tasker task into an apk - i tried it alittle bit right now but it seems not to work as expected, it will not launch the Termux. Maybe it needs a little bit more configuration to get it working.
Otherwise you can create a widget with a shortcut to a Tasker task and that seemed to work right away - no apk this way though but you can use it like an icon on the homescreen.
Title: Re: Compile to a tablet?
Post by: alpine on October 29, 2021, 10:20:51 am
No, no APK, just an executable for the terminal.
Sorry, my error. I presumed *.apk (laz4android+LAMW) vs native executable (Termux+fpc).
 
But wait, did you produce an APK using Termux?
No. Considering all additional stuff needed I didn't even think its possible.
Title: Re: Compile to a tablet?
Post by: regressist on October 29, 2021, 06:38:21 pm
Change the target OS to Android, CPU to Arm, and Target processor to ARMV7A

If you try to compile, you'll see a similar error. When you check the messages, the linker was unable to find one of the files, named: crtbegin_dynamic.o. This file comes with Android NDK. There are a few copies for each Android API version depending on the target processor.

To save you from needing to install the NDK, I'll make a guess and attach a zip file with the needed files. Expand the compressed file and point the test project to it using:

Compiler Options - Paths - Libraries

Note: when you are fed up of supporting just say that, I do not want to disturb you too much!

Don't worry about it.

Done, thanks a lot. Now I have a file without extension which I suppose is the executable.

I suppose I have to transfer it to the tablet, chmod like you said before and run. I do it only when you say that because I am afraid to make mistakes on the tablet, and there I would be lost, I do not have a virtual machine to start again

To the guy who was asking about the nonnative OS, the Galaxy 10 (and also Toshiba with the AT100, in agreement I guess) after version 4.4 stopped upgrading very deceptively I believe since the hw was still good, they want us to buy a new tablet every other year. So someone suggested me after a few years to install a new version not from Samsung, I have now Android 7, but handicapped, it works only partially, e.g. the browser crashes, and I am not able to transfer large files to the pc. But for this which is only a few KB I could use even bluetooth (I hope)
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 29, 2021, 08:09:54 pm
To the guy who was asking about the nonnative OS, the Galaxy 10 (and also Toshiba with the AT100, in agreement I guess) after version 4.4 stopped upgrading very deceptively I believe since the hw was still good, they want us to buy a new tablet every other year. So someone suggested me after a few years to install a new version not from Samsung, I have now Android 7, but handicapped, it works only partially, e.g. the browser crashes, and I am not able to transfer large files to the pc. But for this which is only a few KB I could use even bluetooth (I hope)

I was the gentleman who was trying to help by finding that out. Refer to me as "guy" if you like, but I don't...

The major reason I was asking was because I was trying to fond out whether you thought that by rooting the tablet it was now "non-native". Or alternatively you were referring to the way you were driving Lazarus: your phrasing was a bit vague.

OK, this isn't really the place to discuss the care and feeding of Androids, but can you remember what you used: CyanogenMod or some derivative? I've been through this with a rather less prominent brand and ended up with CyanogenMod 13 (? Android 6.0.1) tailored for the specific "phablet" concerned, most of the stuff works and it's certainly good enough to be a useful development tool.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on October 29, 2021, 08:53:51 pm
I was the gentleman who was trying to help by finding that out. Refer to me as "guy" if you like, but I don't...

The major reason I was asking was because I was trying to fond out whether you thought that by rooting the tablet it was now "non-native". Or alternatively you were referring to the way you were driving Lazarus: your phrasing was a bit vague.

OK, this isn't really the place to discuss the care and feeding of Androids, but can you remember what you used: CyanogenMod or some derivative? I've been through this with a rather less prominent brand and ended up with CyanogenMod 13 (? Android 6.0.1) tailored for the specific "phablet" concerned, most of the stuff works and it's certainly good enough to be a useful development tool.

MarkMLl
Hi,

if your question is on which Android 7 I installed (with large help!) it is this

http://androidbiits.com/samsung-galaxy-tab-10-1-gt-p7510-android-7-0-nougat-aosp-rom/

but even though I do not follow that page from 3 years and might have been fixed, I do not suggest you to install it.

Cheers

Sergio
Title: Re: Compile to a tablet?
Post by: engkin on October 29, 2021, 09:31:46 pm
Done, thanks a lot. Now I have a file without extension which I suppose is the executable.

I suppose I have to transfer it to the tablet, chmod like you said before and run. I do it only when you say that because I am afraid to make mistakes on the tablet, and there I would be lost, I do not have a virtual machine to start again

Yes, that file is the executable. There is nothing to worry about, any mistakes will not cause any major problem. Simply it either works or it does not. In the latter case, it might give a message explaining why it would not run.

Are you familiar with a way to transfer files between your Galaxy and your PC?
Title: Re: Compile to a tablet?
Post by: regressist on October 29, 2021, 10:03:43 pm

Yes, that file is the executable. There is nothing to worry about, any mistakes will not cause any major problem. Simply it either works or it does not. In the latter case, it might give a message explaining why it would not run.

Are you familiar with a way to transfer files between your Galaxy and your PC?

Yes, if the link works I will do with it otherwise I will try with bluetooth. I'll let you know

Thanks again
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 29, 2021, 11:08:15 pm
but even though I do not follow that page from 3 years and might have been fixed, I do not suggest you to install it.

I wouldn't dream of it for a moment. I was trying to find out what you were on about so that we could collectively help you, since you're the one who pleads limited experience.

MarkMLl
Title: Re: Compile to a tablet?
Post by: engkin on October 30, 2021, 02:06:12 am
but even though I do not follow that page from 3 years and might have been fixed, I do not suggest you to install it.
I wouldn't dream of it for a moment. I was trying to find out what you were on about so that we could collectively help you

Thank you for asking. Your question lead him to provide a link that included the model number, Samsung GT-P7510, which helped pinpoint the exact CPU, Cortex-A9 and using ARMv7-A should be the correct instruction set.
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 30, 2021, 10:06:37 am
Thank you for asking. Your question lead him to provide a link that included the model number, Samsung GT-P7510, which helped pinpoint the exact CPU, Cortex-A9 and using ARMv7-A should be the correct instruction set.

Glad to be able to help in a very small way.

For those tinkering with Termux: can anybody say whether the pthreads library is still packaged strangely? That used to be one of the few sticking points with more advanced programming, but I've not looked in detail for more than three years.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on October 30, 2021, 12:39:45 pm
Last news.
I am able to transfer files (probably only small size but for me it's enough). BUT I am not allowed to change permissions for the file; I remember that when we changed the os (actually to 5 and later on to 7) we rooted it but later on for some reasons in the various attempts to improve the poor performances sometimes I got some messages that I was not a superuser or similar. There is a SuperSU application installed, which I probably used.
Sorry for this, this probably is a killer, my complete ignorance and a system already garbled are a huge hurdle for anybody I suppose
Thanks a lot anyway

Sergio
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 30, 2021, 12:48:06 pm
This certainly shouldn't be a killer, and I would urge you to watch out for late responses (it's a weekend, so there might not be as much activity here as normal).

In the worst case you might end up having to install something like Termux anyway, simply to allow you to run chmod or whatever is needed... that should also allow you to use e.g. sftp which doesn't mess around with file permissions in transit.

The fact that people (myself included) have run the compiler successfully on the target system using Termux suggests that this is solvable, allowing you to develop comfortably on a host PC.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on October 30, 2021, 01:10:57 pm
This certainly shouldn't be a killer, and I would urge you to watch out for late responses (it's a weekend, so there might not be as much activity here as normal).

In the worst case you might end up having to install something like Termux anyway, simply to allow you to run chmod or whatever is needed... that should also allow you to use e.g. sftp which doesn't mess around with file permissions in transit.

The fact that people (myself included) have run the compiler successfully on the target system using Termux suggests that this is solvable, allowing you to develop comfortably on a host PC.

MarkMLl


Thank you, of course I will watch with huge interest, I hope it is not too frustrating for you to follow this issue!!
Title: Re: Compile to a tablet?
Post by: engkin on October 30, 2021, 01:39:18 pm
I am able to transfer files (probably only small size but for me it's enough). BUT I am not allowed to change permissions for the file; I remember that when we changed the os (actually to 5 and later on to 7) we rooted it but later on for some reasons in the various attempts to improve the poor performances sometimes I got some messages that I was not a superuser or similar. There is a SuperSU application installed, which I probably used.

This is normal for Android. To control permissions, each apk application is run under a different "user" account. When you grant an application some permission, like access to your GPS location, you are giving its "user" account that permission.

On a rooted device, each account/app can request a superuser power.  As a result you get a pop-up window asking you if you would like to allow the app to have superuser power. Typically on Android this window will disappear, if you don't respond, within 10 or 15 seconds rejecting the request. This detail depends on which Superuser app you have.

Test chmod again but this time request superuser power. You do that by typing su:
Code: Text  [Select][+][-]
  1. su chmod 755 ./yourFileName

Or su alone.

Title: Re: Compile to a tablet?
Post by: MarkMLl on October 30, 2021, 01:46:21 pm
Not at all frustrating. I hope you're not too offended when I have to remind everybody that you're an admitted non-expert :-)

As I've said (but not necessarily in this thread) I've played with FPC running directly on an x86_64-based tablet using Termux in the past, and just to check that the basics still worked I loaded Termux onto my old development phablet a few days ago and was able to ssh into it (i.e. get a shell over a network connection) which implies sftp (file transfer) should also work. The implication of that is that FPC should run on an Android device itself and be controllable from a desktop computer, but something sophisticated like Lazarus might not because of the threads library problem (unless it's been fixed over the last three years, but that is related to the Android architecture rather than being directly fixable by either the Termux or FPC/Lazarus developers).

MarkMLl
Title: Re: Compile to a tablet?
Post by: ojz0r on October 30, 2021, 02:43:04 pm
An alternative to sftp could be rsync over ssh, i use that to sync files to/from my phone (also works in Termux).
Title: Re: Compile to a tablet?
Post by: regressist on October 30, 2021, 05:00:14 pm

This is normal for Android. To control permissions, each apk application is run under a different "user" account. When you grant an application some permission, like access to your GPS location, you are giving its "user" account that permission.

On a rooted device, each account/app can request a superuser power.  As a result you get a pop-up window asking you if you would like to allow the app to have superuser power. Typically on Android this window will disappear, if you don't respond, within 10 or 15 seconds rejecting the request. This detail depends on which Superuser app you have.

Test chmod again but this time request superuser power. You do that by typing su:
Code: Text  [Select][+][-]
  1. su chmod 755 ./yourFileName

Or su alone.


Thanks. When I tried su chmod 755 ./FileName I had a pop-up and pushed granted, on the display I got
 
tmp-mksh: 755: not found

Then I tried su alone and got #, then typed chmod 755 ./file , I got no message but upon ls -al the rights of the file are not changed and if I type the name of the file I get

tmp-mksh:filename: not found
Title: Re: Compile to a tablet?
Post by: regressist on October 30, 2021, 05:08:56 pm
Not at all frustrating. I hope you're not too offended when I have to remind everybody that you're an admitted non-expert :-)

As I've said (but not necessarily in this thread) I've played with FPC running directly on an x86_64-based tablet using Termux in the past, and just to check that the basics still worked I loaded Termux onto my old development phablet a few days ago and was able to ssh into it (i.e. get a shell over a network connection) which implies sftp (file transfer) should also work. The implication of that is that FPC should run on an Android device itself and be controllable from a desktop computer, but something sophisticated like Lazarus might not because of the threads library problem (unless it's been fixed over the last three years, but that is related to the Android architecture rather than being directly fixable by either the Termux or FPC/Lazarus developers).

MarkMLl

Thank you Mark, anyway I do not understand practically one single sentence of what you wrote!!
Anyway now I think I am SU from what I wrote above
Title: Re: Compile to a tablet?
Post by: engkin on October 30, 2021, 06:32:16 pm
Thanks. When I tried su chmod 755 ./FileName I had a pop-up and pushed granted, on the display I got
 
tmp-mksh: 755: not found

Then I tried su alone and got #, then typed chmod 755 ./file , I got no message but upon ls -al the rights of the file are not changed and if I type the name of the file I get

tmp-mksh:filename: not found

Yes, the name of the file alone will not work, unlike Windows. You need to put period slash ./ before it's name.

Unfortunately I will not be around a computer for some hours. As soon as I get a  chance I'll try it on my side and give you a more accurate step.

At least now we know your device is rooted. :)
Title: Re: Compile to a tablet?
Post by: MarkMLl on October 30, 2021, 07:00:48 pm
I'm not sure where this tmp-mksh comes into it, but to expand on one detail:

Yes, the name of the file alone will not work, unlike Windows. You need to put period slash ./ before it's name.

On Windows and other DOS-derivatives, the current directory (./) is implicitly on the execution path. On unix derivatives including Linux it's not, doctrine being that there's too much risk that a user will accidentally execute something he's just created when he really wanted something in /usr/bin.

So if you have a file fred in the current directory, you have to execute it by typing  ./fred

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on October 30, 2021, 08:18:44 pm
Yes, the name of the file alone will not work, unlike Windows. You need to put period slash ./ before it's name.

Unfortunately I will not be around a computer for some hours. As soon as I get a  chance I'll try it on my side and give you a more accurate step.

At least now we know your device is rooted. :)

You are right you told me. But it does not run anyway, I get

tmp-mksh: file: can't execute: permission denied

I guess because it is still a read/write only file.

Take your time, even two days, this is just for fun, and thanks again a lot
Title: Re: Compile to a tablet?
Post by: alpine on October 30, 2021, 09:04:36 pm
Not at all frustrating. I hope you're not too offended when I have to remind everybody that you're an admitted non-expert :-)

As I've said (but not necessarily in this thread) I've played with FPC running directly on an x86_64-based tablet using Termux in the past, and just to check that the basics still worked I loaded Termux onto my old development phablet a few days ago and was able to ssh into it (i.e. get a shell over a network connection) which implies sftp (file transfer) should also work. The implication of that is that FPC should run on an Android device itself and be controllable from a desktop computer, but something sophisticated like Lazarus might not because of the threads library problem (unless it's been fixed over the last three years, but that is related to the Android architecture rather than being directly fixable by either the Termux or FPC/Lazarus developers).

MarkMLl

Thank you Mark, anyway I do not understand practically one single sentence of what you wrote!!
Anyway now I think I am SU from what I wrote above
Considering what Mark said, I've just performed the following steps with Termux on my phone (it is not rooted):
Code: Text  [Select][+][-]
  1. $ whoami
The answer was something like: u0_a322
Code: Text  [Select][+][-]
  1. $ pkg install openssh
  2. $ passwd
  3. $ sshd

On second line I've entered a password for the current user (u0_a322)

Then on a Windows box you can use scp command to transfer files, including your pascal sources, and I presume, you can copy also your binaries generated from laz4android.
Code: Text  [Select][+][-]
  1. $ scp -P 8022 test.pas u0_a322@192.168.1.114:~
8022 is the port on which the sshd listens, the 192.168.1.114 is the IP of my phone, test.pas is the file. The ~ marks the home directory on the destination. It will ask for password, which is the same given to the passwd above.

The thing is that the copied files will have the same owner as the user who started sshd, namely u0_a322. Thus you don't need root permissions to execute:
Code: Text  [Select][+][-]
  1. $ chmod +x binaryfile
i.e. to mark it as executable.

Further, I used a WinSCP program on my PC - it works with SCP protocol and has a synchronization function (Commands/Synchronize...) - similar to rsync, but with Window-ish GUI.

In short - if you install sshd on your Termux, you'll be able to chmod without root permissions (su), and you can install program like WinSCP to easily synchronize directories between tablet and the PC.




Title: Re: Compile to a tablet?
Post by: MarkMLl on October 30, 2021, 09:23:33 pm
The thing is that the copied files will have the same owner as the user who started sshd, namely u0_a322. Thus you don't need root permissions to execute:
Code: Text  [Select][+][-]
  1. $ chmod +x binaryfile
i.e. to mark it as executable.

I think that's sound advice. We need to avoid the situation where the file transfer is being done by some Android implicit user but subsequently OP is using Termux or some other shell as a different user and as a result of that is neither able to run a program nor change its mode.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on November 17, 2021, 07:01:52 pm

Yes, the name of the file alone will not work, unlike Windows. You need to put period slash ./ before it's name.

Unfortunately I will not be around a computer for some hours. As soon as I get a  chance I'll try it on my side and give you a more accurate step.

At least now we know your device is rooted. :)

Sorry to bother you again: can I assume that there is no way to change the execution rights of the file (at least at my low level)?

Thanks
Title: Re: Compile to a tablet?
Post by: engkin on November 18, 2021, 03:58:57 pm
Try to put the file in:
/data/local/tmp

And change its execution rights there.
Title: Re: Compile to a tablet?
Post by: regressist on November 18, 2021, 08:25:00 pm
Try to put the file in:
/data/local/tmp

And change its execution rights there.


WONDERFUL, it works. I appreciate a lot your support.

I think I was lucky: you must be a top class programmer!

Thanks a lot

Sergio
Title: Re: Compile to a tablet?
Post by: regressist on November 20, 2021, 12:52:33 pm
This certainly shouldn't be a killer, and I would urge you to watch out for late responses (it's a weekend, so there might not be as much activity here as normal).

In the worst case you might end up having to install something like Termux anyway, simply to allow you to run chmod or whatever is needed... that should also allow you to use e.g. sftp which doesn't mess around with file permissions in transit.

The fact that people (myself included) have run the compiler successfully on the target system using Termux suggests that this is solvable, allowing you to develop comfortably on a host PC.

MarkMLl

Are you saying that with Termux I could take the precompiled file and change the execution rights without being root?
Title: Re: Compile to a tablet?
Post by: MarkMLl on November 20, 2021, 01:51:00 pm
Are you saying that with Termux I could take the precompiled file and change the execution rights without being root?

I quoted a message which said that explicitly earlier, and I've previously said that sftp preserved permissions. Why- have you tried it and found it didn't work? >:-)

Sorry to sound like a grouch, but I've got things to do and limited daylight to do them.

I've just checked VERY briefly, and if I run sftp on an Android "Phablet" to get a file from a local PC the *user's* rwx rights are preserved, but the group and other rights are masked out. However I was able to chmod the file to 777 without having to do anything special (i.e. no sudo etc.).

Note that I said VERY briefly there. I'd normally log into the device using ssh so that I had a decent keyboard and screen on the PC, but I need to refresh my memory of how to do it.

Note also that permission handling could possibly be changed by (the Linux kernel that is part of) different versions of Android.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on November 20, 2021, 04:41:58 pm
Are you saying that with Termux I could take the precompiled file and change the execution rights without being root?

I quoted a message which said that explicitly earlier, and I've previously said that sftp preserved permissions. Why- have you tried it and found it didn't work? >:-)

Sorry to sound like a grouch, but I've got things to do and limited daylight to do them.

I've just checked VERY briefly, and if I run sftp on an Android "Phablet" to get a file from a local PC the *user's* rwx rights are preserved, but the group and other rights are masked out. However I was able to chmod the file to 777 without having to do anything special (i.e. no sudo etc.).

Note that I said VERY briefly there. I'd normally log into the device using ssh so that I had a decent keyboard and screen on the PC, but I need to refresh my memory of how to do it.

Note also that permission handling could possibly be changed by (the Linux kernel that is part of) different versions of Android.

MarkMLl


Thanks for your reply, I just read again the whole thread because I realized that it's a (safe) pity that I can not run easily a program already compiled on ANY android device without being root. But I can do it on any windows PC... damn it! Of course I did not try your solution because I do not even know where to start (!!), I transferred the executable to a 1+1 phone but I was not able to repeat what done on the tablet simply because it is not rooted (and even if so I do not know if I should recompile it for its processor, but this is another problem).

Please do NOT waste your time to reply, I will monitor the page every while in case someone is willing to reply to these questions:
1) which tools should I use to transfer the file (on pc virtual machines, XP or Vista; termux I guess on android)
2) can I do this via usb cable (I mean without connecting the VM to internet which I can not do)?
3) is this feasible without being an expert?

Thanks
Title: Re: Compile to a tablet?
Post by: engkin on November 20, 2021, 04:59:49 pm
Just to clarify, one of my test phones is not rooted and it is able to run my terminal apps. I don't have su/superuser. I have to use data/local/tmp or a folder inside the terminal emulator app.
Title: Re: Compile to a tablet?
Post by: MarkMLl on November 20, 2021, 05:31:25 pm
Please do NOT waste your time to reply, I will monitor the page every while in case someone is willing to reply to these questions:
1) which tools should I use to transfer the file (on pc virtual machines, XP or Vista; termux I guess on android)
2) can I do this via usb cable (I mean without connecting the VM to internet which I can not do)?
3) is this feasible without being an expert?

Time extending somebody's knowledge and experience is never wasted, particularly if zhe's keen and cooperative. I'll try to take a bit more of a look now that it's getting darker but (1) Putty (2) assume that both the Android device and your PC appear on the local LAN with addresses allocated via DHCP etc. and (3) yes, but you might need to start off by Googling for some simple texts on driving a Linux/unix shell over SSH.

Obligatory xkcd: https://xkcd.com/2542

MarkMLl
Title: Re: Compile to a tablet?
Post by: ojz0r on November 20, 2021, 07:22:36 pm
1) which tools should I use to transfer the file (on pc virtual machines, XP or Vista; termux I guess on android)
2) can I do this via usb cable (I mean without connecting the VM to internet which I can not do)?
3) is this feasible without being an expert?

If you connect your phone to the usb you should get a promt if you want to charge, move photos, or move files - select files. Then your phone should show up in the computers file system as a drive (your phone needs to be unlocked) and you should be able to browse the phones folders. I would put the files in the "download" folder and then use Termux to move them to its ~/home.
Title: Re: Compile to a tablet?
Post by: MarkMLl on November 20, 2021, 08:19:47 pm
OK, here's a very quick experiment. It's not comprehensive, and you'll need to read around a bit... sorry, but I don't have much time.

I've got a "phablet" here which (I find) already has Termux installed, I did this a couple of years ago but forget the detail.

If I login locally (i.e. Termux's own "console" shell session on the Android screen) and run this

Code: Text  [Select][+][-]
  1. $ whoami
  2. u0_a86
  3.  
  4. $sshd
  5.  
  6. $ netstat -an | grep 22
  7. tcp        0      0 0.0.0.0:8022            0.0.0.0:*               LISTEN    
  8.  

Note the unix convention that a leading $ indicates the prompt. i.e. you don't type that.

That's showing you that the user Android/Termux has set up is called u0_a86, that you can start the ssh daemon (server) and that SSH is listening on port 8022 (I can't remember how I set that up, the standard one is 22).

If you now do this

Code: Text  [Select][+][-]
  1. $ netstat -an | grep :8022
  2. tcp        0      0 0.0.0.0:8022            0.0.0.0:*               LISTEN    
  3. tcp        0      0 172.27.16.176:8022      172.27.16.1:33104       ESTABLISHED
  4. tcp6       0      0 :::8022                 :::*                    LISTEN    
  5.  

you can see that it's listening on the dotted quad 172.27.16.176.

Finally, use passwd to give that user a password.

Now go to a PC, I'm using Linux. There's two things you can do:

Code: Text  [Select][+][-]
  1. ~$ ssh -p 8022 u0_a86@172.27.16.176
  2.  
  3. u0_a86@172.27.16.176's password:
  4.  
  5. X11 forwarding request failed on channel 0
  6.  
  7. Welcome to Termux!
  8.  
  9. ...
  10.  
  11. $ ls
  12. pstalk-x86_64-linux-gtk2
  13.  
  14. $ rm pstalk-x86_64-linux-gtk2
  15.  
  16. $ exit
  17.  

Let me explain what you're seeing. You've got a $ prompt on the PC, you're running ssh to connect to the Android device, you're getting various login screed from Termux on the Android device and then a prompt. At the prompt you're running ls to list the files stored in that user's home directory, you see one and remove it, and then you exit the shell session.

Back on the PC, switch to a directory with a compiled program in it. Then use the sftp command to copy that program to the Android device, then quit the transfer session.

Code: Text  [Select][+][-]
  1. ~$ sftp -P 8022 u0_a86@172.27.16.176
  2. u0_a86@172.27.16.176's password:
  3. Connected to u0_a86@172.27.16.176.
  4.  
  5. sftp> put pstalk-x86_64-linux-gtk2
  6. Uploading pstalk-x86_64-linux-gtk2 to /data/data/com.termux/files/home/pstalk-x86_64-linux-gtk2
  7. pstalk-x86_64-linux-gtk2                                                                                 100%   24MB   4.8MB/s   00:05    
  8.  
  9. sftp> quit
  10.  
  11. ~$ ssh -p 8022 u0_a86@172.27.16.176
  12. u0_a86@172.27.16.176's password:
  13. X11 forwarding request failed on channel 0
  14.  
  15. Welcome to Termux!
  16.  
  17. ...
  18.  
  19. $ ls -l
  20. total 24628
  21. -rwx------ 1 u0_a86 u0_a86 25216312 Nov 20 19:10 pstalk-x86_64-linux-gtk2
  22.  
  23. $ exit
  24. logout
  25. Connection to 172.27.16.176 closed.
  26.  

Note a couple of things. Despite being related, the ssh and sftp clients use a different option letter to specify the port: on unix case is significant. If you're using e.g. putty or Teraterm as a client things will be different: read the docs.

Once logged in, you use exit to leave a shell session and quit to leave a transfer session (exit might also work here, depending on variant).

That's all very fast I'm afraid, but is hopefully a taste that stuff /does/ work.

As I've said elsewhere, I've had FPC running under Termux /but/ some of the libraries are packaged differently which gave problems.

(Later:)

When I previously had FPC on a tablet it was x86_64 (amd64) rather than ARM. There's a whole lot of detail I can't remember, I might have needed to do a special build to work round some path issues.

On the phablet I've currently got I can see

Code: Text  [Select][+][-]
  1. $ cat /proc/cpuinfo
  2. Processor       : AArch64 Processor rev 2 (aarch64)
  3. processor       : 0
  4. BogoMIPS        : 26.00
  5. Features        : fp asimd aes pmull sha1 sha2 crc32
  6. CPU implementer : 0x41
  7. CPU architecture: AArch64
  8. CPU variant     : 0x0
  9. CPU part        : 0xd03
  10. CPU revision    : 2
  11.  
  12. Hardware        : MT6795
  13.  

I've quite simply not got the time to do much more but I'm fairly confident that a cross-compiled file could be moved between systems... in any event there's people here with far more experience than I.

The one thing I would warn about is that on Linux, library symlinks are- AIUI- fully resolved at linkage time. The implication of this is that if the development libraries differ substantially from the target system there's a risk of problems: from memory the one that brought me up short in the past was libpthreads (?) which is handled in an arguably non-standard fashion on Android.

MarkMLl
Title: Re: Compile to a tablet?
Post by: regressist on November 20, 2021, 10:06:21 pm
My friends, engkin, MarkMLI, ojz0r: UNBELIEVABLE. I started again the Terminal and made (just to see where it would go)

> cd

it went inside a long dir which ended in something like home-app (I do not remember now, see down); I made

> cp /sdcard/filename .
> chmod 755 ./filename

AND IT RUN! Without even recompilation! (This is why I can not give now the full path where it went, the screen is scrolling).

Mark thanks a lot for the long explanation, I will try to understand it, even though I am not happy on installing a tool in the pc (and the virtual machines can not go on internet...). I will see now if I can do it also on my new phone with the same steps... I will let you know if I manage to increase the array of devices running this stuff.
Title: Re: Compile to a tablet?
Post by: MarkMLl on November 20, 2021, 10:21:00 pm
Mark thanks a lot for the long explanation, I will try to understand it, even though I am not happy on installing a tool in the pc (and the virtual machines can not go on internet...). I will see now if I can do it also on my new phone with the same steps... I will let you know if I manage to increase the array of devices running this stuff.

The only extra thing you'd need on the PC would be an ssh client (which will generally include sftp), and in general I'd expect your corporate IT/MIS people to be have something appropriate.

Apart from that I'm anticipating that you'll read the somewhat-coherent stuff I posted and raise any points you want explained... I'm a fairly experienced technical author but sometimes one lacks the time to "do it right".

MarkMLl
TinyPortal © 2005-2018