Creating APK for Android app



  • I'm trying to get Qt Creator going for Android development, and I've been using one of the example applications as a test, but I can't seem to get Qt to generate an APK file.

    I'm using Qt Creator 2.7.2 "Based on Qt 5.1.0" which I'm running under Windows 7. The example application I'm trying to compile is calqlatr (located in the directory Qt5.1.0\5.1.0\mingw48_32\examples\quick\demos\calqlatr) and I'm trying to compile it for Android for ARM.

    If I open the project and "build all", it successfully builds it and creates a .so file, but no .apk. There's an option in the menu to "Publish Project", but that brings up a Publishing Wizard dialog that informs me that Publishing is currently not possible for the project. If I try to run the app by clicking the green arrow, it launches an Android emulator, and Qt Creator stops responding until I close the emulator (the app itself does not appear to run up in the emulator).

    The Android project notes suggest that Qt Creator's default deployment method should be suitable for distribution of the app:
    http://doc-snapshot.qt-project.org/qt5-stable/qtdoc/platform-notes-android.html

    ... but in my case it just doesn't seem to be creating a .apk file when I hit deploy, just launching the emulator. Is there a setup or configuration step I might have missed?



  • First check the deployement options, IIRC the default option is using Ministro to automatically load and install the Qt libraries and when you launch the emulator Ministro is not installed there.

    if that's not the cause of your problem ...

    When you click on the green arrow besides launching the emulator or connecting to an android device connected via USB, Qt Creator start building the .apk (by compiling inside it the startup Java files and then adding the .so libraries).
    if the "apk build" is successfull you will find the apk
    in (PROJECT_FOLDER)/android/bin
    and the .apk you are looking for is
    (PROJECT_NAME)-debug.apk
    Even if you are building a release version the .apk name will contain -debug, but it will use the release libraries.

    If you can't find the .apk there, probably something has gone wrong in configuring the Android SDK or ant
    (usually it's a matter of environment variables defined incorrectly or missing).
    Check if JAVA_HOME points to the java SDK
    and if inside QTCreator Tools->Options->Android
    "Android SDK location", "Android NDK location"
    "ant location" and "jdk location" are properly set.

    Also be careful about what GCC version you select
    IIRC if you use the precompiled Qt 5.10. for Android libraries
    the correct one is "Android GCC (arm4-6)".

    After you are sure the previsou settings etc. are correct, try to run it again and check the messages in the "compile output" window after you click the green arrow, the apk build and deployement is handled like an "extra compilation step" until the apk starts running.
    In the compile output window you will see messages about what files are being compiled and then added to the apk, what library binaries are included, etc. and there will be error messages is something is going wrong.

    Besides that, I don't use the emulator, but when using an external android device (set with debug/development mode active and connected via USB) sometimes the first time I try to deploy the apk it generates an error.
    But the second time everything goes smoothly (i guess the first time it starts the adb.exe process but too slowly, the second time adb.exe is already running and deployement goes correctly).



  • Thanks, L.MCH

    The Deploy configuration is set to "Use Qt libraries from device" rather than "Install Ministro". I have connected an Android device via USB, but Qt Creator still launches the emulator - I'm not sure what changes I need to make to tell it to deploy to the device instead.

    I am using Android GCC (arm4-6). I don't see anything incorrect in the directories I've put in to the Android configuration page, though the Java JDK is under "Program Files", and Qt seems to have problems with spaces in paths, so perhaps that could cause a problem? I'm worried if I move the Java installation, other programs that require it will not be able to find it, since that's the default installation location for it.

    When I press the arrow to deploy and run, it launches the emulator, but nothing happens, and once I shut the emulator down, Qt Creator reports:
    12:37:38: Please wait, searching for a suitable device for target:android-18.
    Error while building/deploying project calqlatr (kit: Android for arm (GCC 4.6, Qt 5.1.0))
    When executing step 'Deploy to Android device'

    There is no bin directory created, so I suspect that the reason it can't deploy is because the apk build is not being done.



  • I dont think that you have an android 4.3(api level 18) device. So make sure you are using a compatible api level for your android version.



  • To use an Android device for software development, you have to activate "USB debugging" in "Developer Settings" and have the ADB drivers installed on your pc.
    It always works on unlocked/rooted devices, but on locked devices it depends on manifacturers' settings.

    Anyway, as Monster said, either set in the "Projects" build/run another minimal api level or download (using the Android SDK manager) a system image for api level 18.



  • Ahhhhh. I was using api level 18, but the device I was trying to deploy on required level 15. Once I updated with the appropriate Android SDK, and fixed the Apache Ant path to point to the right place, it successfully deployed and ran the example app on the test device. Thanks very much for the help!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.