[Android-development] Attempting a port to Android - Notes and Suggestions

Patricia Aas paaas at cisco.com
Wed Feb 27 11:02:51 CET 2013


On Tue, 26 Feb 2013 20:23:54 +0100, BogDan <bog_dan_ro at yahoo.com> wrote:

> Hi,
> [...]
>
>> B ) Assets should be loaded automatically, without the assets:/ prefix,
>> will probably require changes to AndroidAssetsFileEngineHandler
>
> Searching trough android assets is very expensive, if for every file
> you'll first search assets it will take ages until your application  
> starts,this is the reason why assets:/ prefix is needed.

Yes, however I don't want to search. If the path is assumed to be in  
assets, which it is for all resources, except files you write yourself to  
files, supporting Android as a second/third/.. platform for an existing Qt  
project becomes feasible. Where as now none of the paths in my application  
works, and I will have to make significant code changes to make it work,  
with ifdef __ANDROID__ everywhere.

Things like this :

QLatin1String("images/1080/common/corner_bottomleft.png");
QFile logConfig("etc/default/Trolltech/Log.conf");
loading translation files (which was a bit more than a one-liner)
loading a custom font (which I still haven't been able to hack to work -  
even with all my copying assets to files)

Our application is riddled with these, now these resources are present in  
our INSTALL_ROOT folder when qmake is done. With the exact folder  
structure we want. All I do when packaging is copying all of these  
directories except libs into assets. And then I want it to just work :D

And it doesn't. And it isn't just my code. The qt code has these issues as  
well. It assumes that certain resources are in certain places relative to  
the application directory (eg. qt.conf) or relative to qmldir files (the  
qml plugin libraries) and they are not.

I want to say, for example in qt.conf::Prefix, that all of my resources  
are in assets:/ and all of my paths are relative to assets root. And I  
can't. And even if it did work, I cannot have a qt.conf because it has to  
be in lib, and lib can only have so files as far as I can tell.

For my application to "work" out of the box I have to copy all of my  
resources out of assets, into files. Then I have to copy all of my plugins  
(shared libs) (qml or QGeneric plugins) into files as-well for them to  
load.

Now, I have decided on my "workaround" for now (as discussed on irc), I  
will copy all of my assets and plugins into files (just like I have been  
doing), in any structure that makes Qt happy, I will set my plugin paths  
to files directories, and anything else I need to do, in java code, in  
QtActivity.

Now, my only problem was that it was very slow. After a bit of poking  
around I found that AssetManager::list() (forgive my c++ notation) is dead  
slow. So today I will make an index.txt which contains the paths to all my  
resources when packaging my apk, and I will place it in the root of my  
assets. Then I will read this out and copy all of my resources from assets  
to files on startup with full path to each resource, avoiding using  
AssetManager::list() and recursion. I am hoping that this will give me  
sufficient performance that the startup time will be ok. But it is a hack.

What I really want is this :) :

1) A way to tell Qt that all my external paths are relative to assets root
2) A way to load qml plugins with the qmldirs in assets and the so in libs
3) A way to load QGenericPlugins from libs, even though there is no  
"generic" subdirectory there

Now if I had that, wow, my port would be a dream :D (I hope, I'm not done  
yet...)

> [...]
>
>> E) Custom QtActivity.java::APPLICATION_PARAMETERS should be passed first
>> to main before any other parameters needed by the android port
>
>
> Pending patch :  https://codereview.qt-project.org/49134

Thank you for the patch ! :) And thank you very much for your time.

-- 
Patricia Aas
Developer
Cisco



More information about the Android-development mailing list