The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: prissi on March 13, 2022, 12:56:07 PM

Title: Android version
Post by: prissi on March 13, 2022, 12:56:07 PM
The Android nightly is found under https://github.com/aburch/simutrans/releases/tag/Nightly This is not signed with the regular key (which only Google owns) and thus may clash with an official release in the future on the playstore.

In this thread, please discuss the Android related issues and how to improve usage.

It has been tested under bluestacks (emulator), Fire7 tablet (max speed ca. 5.5 without midi), Samsung S7,  Alcatel One
Simutrans does not start on a Huawei P9 (too little free memory?) and maybe other devices (please reports)

Known issues:
Hangs at the first start with a black screen: please wait a little.
Runs slowly, especially on high resu\olution screens (disable midi and use larger scaling in display options can help)
Title: Re: Android version
Post by: Yona-TYT on March 14, 2022, 01:52:20 AM
Quote from: prissi on March 13, 2022, 12:55:21 PM
Popup message shoudl disappear after some time. Also a popup in the wrong position may be ignored first.
Despite being temporary windows, they can be somewhat annoying since they appear right in the area of the screen where we want to build, it would be more pleasant to have them fixed in a corner away from the center of the screen, that is only on android of course.  8) 
Title: Re: Android version
Post by: Yona-TYT on March 18, 2022, 01:04:20 PM
It would be very useful to have a virtual "ctrl" key on the screen for android or better touch devices.

Only for use in combinations with tools.  :P
Title: Re: Android version
Post by: Vladki on March 18, 2022, 10:41:14 PM
I tried on Oneplus 3T (phone 6GB RAM).  It works but is practically unplayable. The UI is so small that I cannot hit the controls, e.g.  close a window. Is there any way to deal with high DPI screens? (FullHD @ 5.5")
Also I had the feeling that even if I touch the correct spot, it sometimes does not react at all. A helpful thing would be to use the "back" key as "ESC" to close current windows.
Title: Re: Android version
Post by: prissi on March 19, 2022, 01:48:35 AM
Simutrans reads out the dpi setting and should adjust accordingly (but this was removed by error). r10558 should again autoscale the display. (It may be still small, depending on your dpi settings). Autoscale also force 1280 like maximum width otherwise performance may be really bad. (Under 1 simloop)

Please test again.
Title: Re: Android version
Post by: Vladki on March 21, 2022, 10:45:50 PM
Yes it is much better now. Although manual setting of the scale (dpi) is not very comfortable.

How do I do ctrl + click on touch screen?
Title: Re: Android version
Post by: prissi on March 22, 2022, 01:41:30 AM
You cannot right now. Maybe there is a control field or special tool needed for this.

The back button (if there) should close the last window.
Title: Re: Android version
Post by: Vladki on March 22, 2022, 10:02:16 AM
The back button closes all windows in my experience.
Title: Re: Android version
Post by: prissi on March 22, 2022, 12:27:10 PM
You are right, my mistake. r10586 should do the same as delete, i.e. only close the topmost window.
Title: Re: Android version
Post by: MobileGlotze on April 05, 2022, 03:13:58 PM
Can't install it on my Samsung a51 and galaxy Tab S5e.

Edit: forgot it. I was to stupid. I have to remove the old app. But I lose my save game:/

Title: Re: Android version
Post by: Yona-TYT on April 05, 2022, 03:27:13 PM
Quote from: MobileGlotze on April 05, 2022, 03:13:58 PMCan't install it on my Samsung a51 and galaxy Tab S5e.

Edit: forgot it. I have to remove the old app. But I lose my save game:/


The app should update without having to delete it previously, maybe it is because it is not officially in the play store?. ???
Title: Re: Android version
Post by: MobileGlotze on April 05, 2022, 04:01:17 PM
I don't know. When I save a game I can't find it in the folder. I downloaded pakgerman large and can't find it in the folder. Only pak and pakjapanese.

(https://media.discordapp.net/attachments/752250203712520202/960931616241360926/20220405_175741.jpg)

(https://media.discordapp.net/attachments/752250203712520202/960931615461232640/20220405_175728.jpg)
Title: Re: Android version
Post by: Andarix on April 05, 2022, 05:51:52 PM
pak64.german is not bundled by offical Nightlys.

If installed from within the program, it will be installed to the user directory files.

pak64.german is also part of my Nightlys.
Title: Re: Android version
Post by: prissi on April 07, 2022, 04:47:57 AM
The user files (under data/data) are not accessible for other programs intentionally. You save games should be in the folder save.

The key and name "com.simutrans" changed since November, when the very first build were done.
Title: Re: Android version
Post by: Mishasama on May 21, 2022, 11:18:40 PM
These versions can't be upgrade from the previous nightly versions?
It looks used different signatures for every APK?  :o
Title: Re: Android version
Post by: prissi on May 22, 2022, 12:23:56 PM
The key to the final version is held only by google, I only have an upload key. The apk is singed with a key from krosk, I think. Andarix uses his own key. We could think of a simutrans team developer key to be shared to people releasing their own versions, but the svn number in these cases will be different.

As soon as it is in the play store, it will be automatically updated by google, using the google secret key.

So indeed, we may need a simutrans team key to sign the nightly versions, or release the nightly via google, which seems possible as beta track.
Title: Re: Android version
Post by: Mishasama on May 29, 2022, 04:35:39 PM
Quote from: prissi on May 22, 2022, 12:23:56 PMThe key to the final version is held only by google, I only have an upload key. The apk is singed with a key from krosk, I think. Andarix uses his own key. We could think of a simutrans team developer key to be shared to people releasing their own versions, but the svn number in these cases will be different.

As soon as it is in the play store, it will be automatically updated by google, using the google secret key.

So indeed, we may need a simutrans team key to sign the nightly versions, or release the nightly via google, which seems possible as beta track.
I think you should share key first. Google's review speed is very slow that not suitable for fast version iterations.
Title: Re: Android version
Post by: prissi on May 30, 2022, 12:31:10 PM
I cannot share the final key, since ONLY google has it. I only have a self signed upload key. It is their policy since 2020 or so. Before, you could upload apks with you own key, but this is not accepted for new projects any more.
Title: Re: Android version
Post by: Mishasama on June 02, 2022, 06:16:01 PM
Quote from: prissi on May 30, 2022, 12:31:10 PMI cannot share the final key, since ONLY google has it. I only have a self signed upload key. It is their policy since 2020 or so. Before, you could upload apks with you own key, but this is not accepted for new projects any more.
I mean, first use a shared key among the development team to avoid signature conflicts when installing updates. Do as you say.
Doing so will also test for errors after installing the update.

Otherwise we have to uninstall and reinstall every time.
This makes it impossible to test the actual situation of the average user when installing the upgrade.
Title: Re: Android version
Post by: prissi on June 03, 2022, 12:17:24 AM
As soon as Google finishes reviewing (they complain about the data privacy, even though Simutrans does not harvest any data and the privacy policy says explicitly so) there will be a beta track in the play store with the nightlies.

The github built script cannot use secrets since nobody of the development team has write access to github.com/aburch, which is just updated through a third party server. We could only sign it afterwards after upload to sourceforge.
Title: Re: Android version
Post by: prissi on June 04, 2022, 02:57:58 PM
A recent nightly is now available on the google play store:
https://play.google.com/store/apps/details?id=com.simutrans
Title: Re: Android version
Post by: Yona-TYT on June 04, 2022, 03:36:28 PM

I would like to have in android a "single window mode" for objects such as: objects ground, trees, buildings, ways objects...

It is more practical to have only 1 active window at a time for this type of objects, but this is only for android versions!.  8)
Title: Re: Android version
Post by: makie on June 04, 2022, 08:50:53 PM
fine
I can search and find simutrans in the playstore
ok first entry in the search list is "Train Station 2" but the second is Simutrans
this is fine
now we and all other can install it easy  :D 

ok it is too much for my old tablet but it works
Title: Re: Android version
Post by: prissi on June 05, 2022, 03:44:57 AM
I will try to release the nightlys automatically to the beta track. Then only the windows store is left, which should be easier. Finally, I will do a new release with the much more responsive GUI and the improved sync_step, so one can also do a new online games from all platforms.
Title: Re: Android version
Post by: tuxianer on November 04, 2022, 07:52:19 AM
Hey folks,

I love the version running on Android so far - admittedly playing is rarely on the Tablet/Phone but still I can. One question or point of consideration would it be worthwhile to see if we can create an Fdroid Repo where nightlies (and stable builds) would be automatically released to?

The Play Store of Google can be a prime choice for most but has its limitations on frequent updates, so I was thinking about the FDroid store?
Title: Re: Android version
Post by: prissi on November 04, 2022, 12:26:36 PM
Fdroid requires all compiled ourselves, but we use some precompiled stuff from Pelya. So far, we have no version which compiles standalone, only on github. Compiling for Android means to compile all needed libraries too so the build process is very long and tedious.

For Fdroid, we would need a standalone compiling version on gitlab. If you want to do this, go ahead.
Moreover, the Android version will only update with a stable on the stable branch for th eplaystore, and only testing will get nightly. Otherwise networkgames will nto work. Unfortunately, there is no really good stable Android version in sight right npw. Maybe for a Christmas release ...
Title: Re: Android version
Post by: tuxianer on November 04, 2022, 04:35:46 PM
Hi,

OK was not aware of all the processes associated to it, how could I. Thus the question around fdroid, where would I find the doc on compiling an android version if I want to try my luck out on gitlab?

Cheers
Title: Re: Android version
Post by: prissi on November 05, 2022, 01:28:05 PM
There is a script on the Pelya server which builds simutrans after we patch it. We would need to implement something like that ourselves, i.e. downloading the latest stable SDL2, bz2lib, zstd, freefonts6 and probably others as well, and then move the sources into the right subdirectory and finally first build the libs and then simutrans. That would be entirely a scripting exercise.

Such a package should be able to get uploaded to gitlab and build there. It would also greatly facilitate Android development for Simutrans, to be able to build it outside of github CI.

If one is decently fluent with Android, one could rather make an interface to the native code and use the Android libraries for midi, freefonts, https downloads etc, saving compile time, and hassle with keeping so many libraries working.
Title: Reworking Android build with gradle + CMake [Help Needed]
Post by: Roboron on March 11, 2023, 04:54:18 PM
I've been reworking the build system for Android. I took prissi's advice of starting from scratch, and followed SDL's guide for Android project here. (https://github.com/libsdl-org/SDL/blob/SDL2/docs/README-android.md#building-an-app)

Using gradle + CMake (+ clang) I have succeeded in compiling a Simutrans package, including its libraries.

However, when I try to run it, Simutrans crash with 
Scudo ERROR: misaligned pointer when deallocating address 0x00746f465ec0
Specifically, this is thrown very early at simsys.cc#L1124 (https://github.com/simutrans/simutrans/blob/master/src/simutrans/sys/simsys.cc#L1124)
char buffer[PATH_MAX];
ssize_t const length = readlink("/proc/self/exe", buffer, lengthof(buffer) - 1);
if (length != -1) {
buffer[length] = '\0'; /* readlink() does not NUL-terminate */
argv[0] = buffer; // CRASH

I guess that this may be happening because I'm missing some compilation flags (because it doesn't make much sense that this code is running without issue in the current build). Did some research and the only suggestion I found pointed that the -Oz/-O3 flag may be causing this - however it is not being applied, and if applied the error changes to:

Scudo ERROR: corrupted chunk header at address 0x00746f465ec0
So I am really lost and I don't know how to continue. Any ideas?

-------------------------
I've setup a repository containing the stuff needed to compile this https://github.com/Roboron3042/simutrans-android-cmake

1) Install the android dev tools as usual (sdkmanager, ndk;25.1.8937393, cmake;3.22.1, platform-tools, build-tools;33.0.1, platforms;android-31, see the pipeline for details). openjdk17 needed.
2) Run prepareAndBuild.sh, the script will initialize git submodules (our libraries), compile them (see app/jni/build_libraries.sh for details, it is pretty simple), prepare the assets and sources, and build a debug version of Simutrans.
3) For building again just run ''./gradlew assembleDebug'' (or bundleDebug for a bundle, installDebug to directly install on a connected device, etc...)

There are only some key files to take care of:
build.gradle
app/build.gradle
app/jni/CMakeLists.txt
app/jni/build_libraries.sh
app/src/AndrodManifest.xml
Simutrans' CMakeLists.txt also needed changes to find Android libraries, so I'm using my own fork as submodule.

That's it. I find it quite simple, it is such a pity that I can't get it to run...

I tried to set up  a GitHub pipeline but it is failing at uploading the **** file ('Resource not accessible by integration'). I really don't know how actions work so I gave up on this. I made the release manually.

TODO:
- Obviously first solve the unaligned pointer error.
- libfreetype and libfluidsynth need to be set up. I intentionally left them out until I was able to continue.
- Release and non-arm builds currently disabled.
- Replace SDL's app/src/main/res (image and game name) with our own.
Title: Re: Android version
Post by: Dwachs on March 11, 2023, 06:10:54 PM
No idea, what is causing this. I compiled simutrans with clang and using this scudo-sanitizer, but got no errors.
Title: Re: Android version
Post by: Combuijs on March 11, 2023, 07:35:04 PM
Long time ago that I've seen C++-code, but for me it's odd that you are changing the argv[0] parameter, passed on no doubt by the main function to the sysmain function. Maybe Android is protecting this parameter against writing? Why not using a local string variable instead of modifying argv[0]? Is the changed parameter used later on in the main function?
Title: Re: Android version
Post by: Roboron on March 12, 2023, 01:11:55 AM
Detective Combuijs you solved the case! Just making a local copy of argv[0] allows the program to continue :-)

Now, it doesn't go too far, because it is looking for the base_dir at /data/data/com.simutrans.simutrans/files/ but there is nothing there - so it exits. I wonder where are the assets of the apk...

But that's a problem for another day. Thank you!

EDIT: The assets stay inside the APK, and we can't get them using fopen. Solution may involve copying the assets to external storage where they are expected.
Title: Re: Android version
Post by: Yona-TYT on March 12, 2023, 09:02:50 AM
Nice  8)
Title: Re: Android version
Post by: prissi on March 13, 2023, 02:50:54 AM
Thank you for your efforts on doing that from scratch. It certainly helps that cmake is now supported ...

The base dir should have a single data dir. Having two somewhat indicated that scripts paths are all relative. Hence, the rebuild script may have been called from the wrong directory ...

I tried compiling your script on the commandline of my server. First, it does not work after downloaded you achieve, one has to clone the git. But the git submodule will not survive checking in with SVN ... I think one has to clone them manually in the preparation.

I will try again to get a built system going. SHould be easier now even under windows ...
Title: Re: Android version
Post by: Roboron on March 14, 2023, 05:27:31 PM
The simutrans submodule will be replaced by cloning the SVN/git repo in the final pipeline - it doesn't make much sense to have a fixed version anyway, unlike the libraries.

Good news! I have a build working and running - and the pipeline is now also working!

List of things to do
1. :done:  Solve the unaligned pointer error.
2. :done:  Build with freetype.
3. :done:  Add command line args.
4. :done:  Unpack assets when Simutrans is opened after install.
5. :done:  Build with fluidsynth => This will be a PITA.
6. Check that non-armv8 builds work.
7. :done:  Replace SDL's app/src/main/res (image and game name) with our own.
8. :done:  Check the pakset installer (not working currently).
9. :done:  Simutrans currently crash after open IF the previous time it exited from the menu. SDL's documentation says this can happen if a call to exit() was made, which should be avoided. Apparently, it is crashing at gui_theme_t::themes_init -> pakset_manager_t::load_pak_file -> ... -> register_image.
10. :done: Unpack assets also after update. Currently I have implemented a Java method at Simutrans.java that unpack assets (as Pelya does) if the config/simuconf.tab is not found. However, this should be done not only after first install, but also after upgrading to a new version. Lowes priority for me.
Title: Re: Android version
Post by: MobileGlotze on June 17, 2023, 08:34:43 AM
It's possible to transfer a save game from device to device? On the way I play on smartphone but at home on tablet.