Qt/Andriod app, can't seem to get AndroidManifest incorparated

64 Views Asked by At

I'm new here and this is my first post. I have started to learn Qt and I am now trying to work my way up to a custom calculator app for andriod. unfortunately I am stuck at locking the screen orientation to portrait. I could really use some help because I tried 2 days already to find an answer online but it was no good.

So I started with a qml project and added an AndriodManifest.xml file via the create templet button. that explains how to incorparate that to my build. I added

qt_add_executable(CalculatorApp src/main.cpp
MANUAL_FINALIZATION
)

set_property(TARGET CalculatorApp APPEND PROPERTY
    QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android
)

qt_finalize_executable(CalculatorApp)

to my CMakeLists.txt file. It now looks like this:

cmake_minimum_required(VERSION 3.21.1)

option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
option(BUILD_QDS_COMPONENTS "Build design studio components" ON)

project(CalculatorApp LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)

find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)

if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
    qt_standard_project_setup()
endif()


qt_add_executable(CalculatorApp src/main.cpp
MANUAL_FINALIZATION
)


qt_add_resources(CalculatorApp "configuration"
    PREFIX "/"
    FILES
        qtquickcontrols2.conf
)

target_link_libraries(CalculatorApp PRIVATE
    Qt6::Core
    Qt6::Gui
    Qt6::Qml
    Qt6::Quick
)

if (BUILD_QDS_COMPONENTS)
    include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)

if (LINK_INSIGHT)
    include(${CMAKE_CURRENT_SOURCE_DIR}/insight)
endif ()

include(GNUInstallDirs)
install(TARGETS CalculatorApp
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set_property(TARGET CalculatorApp APPEND PROPERTY
    QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android
)

qt_finalize_executable(CalculatorApp)

and finally my AndriodManifest.xml file:

<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.qtproject.example" android:installLocation="auto" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:versionName="-- %%INSERT_VERSION_NAME%% --">
    <!-- %%INSERT_PERMISSIONS -->
    <!-- %%INSERT_FEATURES -->
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
    <application android:name="org.qtproject.qt.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="-- %%INSERT_APP_NAME%% --" android:requestLegacyExternalStorage="true" android:allowNativeHeapPointerTagging="false" android:allowBackup="true" android:fullBackupOnly="false">
        <activity android:name="org.qtproject.qt.android.bindings.QtActivity" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:label="-- %%INSERT_APP_NAME%% --" android:launchMode="singleTop" android:screenOrientation="portrait" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
            <meta-data android:name="android.app.arguments" android:value="-- %%INSERT_APP_ARGUMENTS%% --"/>
            <meta-data android:name="android.app.extract_android_style" android:value="minimal"/>
        </activity>
    </application>
</manifest>

When I click the run button in Qt Creator the app appears like normal on my andriod device but it always still rotates.

I also took pictures of how my folder structure looks like in my project and will attach them to this post, if by any chance there lies the problem. I also tried writting:

in my CMakeList.txt, which I came across in another post, but that also didn't work. It is also weird that there is no auto-completion in my AndriodManifest file, because in other people's videos I see auto-completion being offered but here it isn't.

I would really appreciate any help I get here because I can't seem to solve this. projectstructure Qt Creator CalculatorApp Structure

0

There are 0 best solutions below