3

I am using qt 5.2 and I have been trying to figure out how to have extra files along with my application when it installs. I want to be able to use adb shell and then cd into data/data/org.qtproject.example.myProjectPath/. I would like to be able to find that file somewhere. I had posted a question about this already but was unable to find answers. Some people did reply and there was mentioning of assets but qt 5.2 doesn't create an assets file. I was also told to try something along the lines of

deployment.files += program
deployment.path = /assets
INSTALLS += deployment

and also

documentation.path = /usr/local/program/doc
documentation.files = docs/*
INSTALLS += documentation

Neither of these I could get to work. I was also given this link but it does not seem to be Android-specific.

Ruslan
  • 18,162
  • 8
  • 67
  • 136
kobihudson
  • 155
  • 1
  • 12

3 Answers3

5

You can use the Qt Resource system. By default, all Qt applications can access the contents of a qrc file using the ":/" prefix or the URL scheme prefix, "qrc:".

The other approach is to deploy the resources into the package's assets directory. It is the best option if you want to achieve better interoperability with the Android APIs. You can access all resources in the directory using the "assets:" prefix. Unlike qrc, this approach is not a cross-platform solution.

When you build your project, a folder named "assets" in created in the Build-Directory/android-build/. After copying your files in the assets directory, you can add these to your pro:

deployment.files += MyFile1
deployment.files += MyFile2
...
deployment.path = /assets
INSTALLS += deployment
Nejat
  • 31,784
  • 12
  • 106
  • 138
  • I dont know if this is quite what I am looking for because I have tried to add it to the qrc file but it is a script so I don't know how to use it. – kobihudson May 13 '14 at 14:02
  • 1
    This is not working for me (Windows host), not sure if either the file is not copied or if androiddeployqt simply deletes the folder before writing to it. – FourtyTwo Nov 13 '17 at 13:36
1

I'm not familiar with qt but you add files that are like music or art or text files that aren't code to a directory named assets on your computer where your code lives.

A typical directory structure might have directories for libs, res, src, and assets. The process that builds the apk will automatically pick up this folder and any files in it and include it in the apk. You can't use shell to look at these files.

To access these files you do so in your java activity class by calling getAssets(). An example of how to open a file from your activity class might be .. .

InputStream is = getAssets().open("yourfile.mp3");

http://developer.android.com/reference/android/content/res/AssetManager.html

Hope this points you in the right direction.

Alicia Cano
  • 200
  • 6
1

A solution that works for me (Qt 5.9.2):

  • add the following line to the .pro file if you don't already have it for e.g. a custom manifest file (folder name doesn't matter for pkg_src):

    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/pkg_src
    
  • create a folder "pkg_src/assets" relative to the .pro file

  • copy the files you need to this folder, either manually or e.g. with a QMAKE_POST_LINK command which copies the files there after the app build.

This is not 100% ideal, since QMAKE_POST_LINK is only executed if there is something to build, but is at least sufficient for my needs.

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
FourtyTwo
  • 1,616
  • 2
  • 15
  • 43