[fpc-pascal] Android porting ideas

Ryan Joseph ryan at thealchemistguild.com
Mon Feb 22 03:26:19 CET 2016


Hey Michalis, thanks for your detailed answers I really appreciate it.

> In Castle Game Engine the whole Pascal code is compiled into an .so
> library (for Android+Arm, though we could also target Android+x86). It
> is then packaged into an apk, with the activity class set to the
> "NativeActivity" Java class.

I see you made a builder tool I’ll have to check out. From the Android tutorials I’ve seen building Android packages seems be pretty forward. You can run/install apps from the terminal also I think based on your documents. That’d be nice to not be in Android Studio if I don’t have to be.

It looks like the majority of the startup code is in castlewindow_android but I was expected to see an OpenGL context (surface view I think in Android). How do you render OpenGL then?

>> 
>> 1) All the file I/O in the FPC RTL is not available so what possible work arounds are there for loading data from files?

> The important thing is that your program data (what you put in apk) is
> *not* stored on disk as normal files. You need to use AssetManager to
> read it. With some helpers, you can just open an "asset file" as a
> Pascal TStream, and then read from there. In CGE, you just use URL
> like "assets:/some_subdirectory/blahblah.png", pass it to any
> file-reading function and it will read the file
> "some_subdirectory/blahblah.png" from your data. More info on
> http://castle-engine.sourceforge.net/tutorial_network.php .

Yeah I see there’s a CastleAndroidAssetManager unit which does this.

So UNIX I/O “works” but you can’t read anything without the asset manager? That doesn’t really make sense but either way using the Asset manager in a stream like you did is just fine. I only need to read the contents of images and XML files anyways.

I was using ReadXMLFile to read the XML file but I assume this is just a helper function that wraps something lower level I could use in conjunction with the asset manager. Is that correct? Can’t find your code for this.

> 
>> 
>> 2) OpenGL functions are not available so how can I call into the Android library? Callback wrappers perhaps?
> 
> You use OpenGL ES for rendering (version 2 or 3, for modern devices).
> Pascal bindings are available already in FPC, see unit GLES20. Of
> course engines like CGE  give you more comfortable API for rendering,
> on top of this.

So internally Android just uses the same C libraries we were using in Pascal? I guess that makes sense but I was thinking EVERYTHING on the system was now Java but that’s not the case I guess. The lesson here is that Android is built on Linux so we’re sharing more than I think.


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list