Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How can I put extra files into my android bundle?
Qt 6.11 is out! See what's new in the release blog

How can I put extra files into my android bundle?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 5.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeoChen
    wrote on last edited by
    #1

    In my code there is a line to load an extra binary file in to my APP, looks as the following:

    QFileInfo graph_binary("./Models/graph_binary.pb");
    

    This file is loaded for a 3rd lib, so I can not use the qrc file management.

    How can I load this file into my Android APP?

    The correspond config for Macs:

    {
    APP_PB_FILES.files = $$PWD/Models/graph_binary.pb
    APP_PB_FILES.path = Contents/MacOS/Models
    QMAKE_BUNDLE_DATA += APP_PB_FILES
    }
    

    For iOS:

    {
    APP_PB_FILES.files = $$PWD/Models/graph_binary.pb
    APP_PB_FILES.path = Models
    QMAKE_BUNDLE_DATA += APP_PB_FILES
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You need to use the correct path to your data. Currently you're using a relative path to your application binary which won't be valid e.g. on iOS.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You need to use the correct path to your data. Currently you're using a relative path to your application binary which won't be valid e.g. on iOS.

        L Offline
        L Offline
        LeoChen
        wrote on last edited by
        #3

        @SGaist Thank you for your suggestion, could you show me an example how to correctly set and reference the pathway?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You have for example QStandardPaths.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            You have for example QStandardPaths.

            L Offline
            L Offline
            LeoChen
            wrote on last edited by
            #5

            @SGaist Thank you for your information. But here my problem is how to put an extra file into the android bundle in the .pro file, Could you also give a configuration example?

            D 1 Reply Last reply
            0
            • L LeoChen

              @SGaist Thank you for your information. But here my problem is how to put an extra file into the android bundle in the .pro file, Could you also give a configuration example?

              D Offline
              D Offline
              Devopia53
              wrote on last edited by Devopia53
              #6

              @LeoChen

              In your case, it is better to use the Android assets file system(read only).
              Like this:

              APP_PB_FILES.files = $$PWD/Models/graph_binary.pb
              APP_PB_FILES.path = /assets/Models
              INSTALLS  += APP_PB_FILES
              

              Then you can access to the data installed using the "assets:/Models/graph_binary.pb".

              L 1 Reply Last reply
              1
              • D Devopia53

                @LeoChen

                In your case, it is better to use the Android assets file system(read only).
                Like this:

                APP_PB_FILES.files = $$PWD/Models/graph_binary.pb
                APP_PB_FILES.path = /assets/Models
                INSTALLS  += APP_PB_FILES
                

                Then you can access to the data installed using the "assets:/Models/graph_binary.pb".

                L Offline
                L Offline
                LeoChen
                wrote on last edited by
                #7

                @Devopia53 said in How can I put extra files into my android bundle?:

                "assets:/Models/graph_binary.pb"

                Thank you for your suggestion. In this way, I have successfully copy the file into the assets folder. However, since I am going to use a 3rd lib to load that file instead of QtCore lib, I get "Not found: assets:/Models/graph_binary.pb".

                Is there a correspond mechanism in Qt as in use of assetManager on Android?

                D 1 Reply Last reply
                0
                • L LeoChen

                  @Devopia53 said in How can I put extra files into my android bundle?:

                  "assets:/Models/graph_binary.pb"

                  Thank you for your suggestion. In this way, I have successfully copy the file into the assets folder. However, since I am going to use a 3rd lib to load that file instead of QtCore lib, I get "Not found: assets:/Models/graph_binary.pb".

                  Is there a correspond mechanism in Qt as in use of assetManager on Android?

                  D Offline
                  D Offline
                  Devopia53
                  wrote on last edited by
                  #8

                  @LeoChen

                  Yes. This feature is similar to Android. Here

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    LeoChen
                    wrote on last edited by
                    #9

                    Well, I kind of give up and use an ugly yet worked method:

                        QString file_location = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
                        QDir t_dir(file_location);
                        if (!t_dir.exists()) {
                            t_dir.mkpath(file_location);
                        }
                        auto t_copy = QFile::copy(":/Models/graph_binary.pb", file_location + "/graph_binary.pb");
                    

                    Then reference the file from the 3rd lib.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved