Skip to content

Building for Android fails with undefined symbol: qt_resourceFeatureZstd #1251

Open
@gambhiro

Description

@gambhiro

I tried to build a small project based on the qml_minimal example for Android.

It was eventually successful. Some issues were configuration specific, but the Zstd issue relates to how the RCC command is composed in crates/qt-build-utils/src/lib.rs.

I installed Qt with the open source online installer to ~/Qt/.

Then installed the Rust targets (x86_64 is for the emulator such as Genymotion):

rustup target add aarch64-linux-android
rustup target add x86_64-linux-android

Cargo should use the correct qmake to find the correct Qt include folders:

In CMakeLists.txt:

if (ANDROID)
    set(qmake_path "$ENV{HOME}/Qt/6.8.3/android_x86_64/bin/qmake6")
endif()

cxx_qt_import_crate(
    MANIFEST_PATH rust/Cargo.toml 
    CRATES simsapa_lib
    LOCKED
    QMAKE ${qmake_path}

    QT_MODULES ...
)

I encountered the following errors:

Error: Missing Qt6QmlImportScanner_DIR

Qt is set to be not found because Qt6QmlImportScanner is not found in the Qt/6.8.3/android_ folders.

In Qt Creator, open Projects > Android Build > Current configuration

Add a Directory entry to the Initial Values tab, so that it will be saved to CMakeLists.txt.user

(TODO: How can this be set in CMakeLists.txt?)

Qt6QmlImportScanner_DIR
/home/<your-username>/Qt/6.8.3/gcc_64/lib/cmake/Qt6QmlImportScanner

Error: undefined symbol: qt_resourceFeatureZstd

ld.lld: error: undefined symbol: qt_resourceFeatureZstd
>>> referenced by qml_module_resources_com_profound_labs_simsapa.qrc.cpp:401 (/home/gambhiro/prods/apps/simsapa-project/simsapa-cxx-qt/simsapa/build/Android_Qt_6_8_2_Clang_x86_64-Debug/./cargo/build/x86_64-linux-android/debug/build/simsapa_lib-044fbcbd79e4a67a/out/qt-build-utils/qrc/qml_module_resources_com_profound_labs_simsapa.qrc.cpp:401)
>>>               699aa1b37edc0ef0-qml_module_resources_com_profound_labs_simsapa.qrc.o:(qResourceFeatureZstd())

Zstd compression has to be disabled for the RCC command to produce .qrc.cpp files which can compile for Android.

The CMAKE_AUTORCC_OPTIONS variable was not picked by CXX-Qt from CMakeLists.txt, e.g. this didn't work:

list(APPEND CMAKE_AUTORCC_OPTIONS "--no-zstd")

So I added the options directly in ‎crates/qt-build-utils/src/lib.rs

"--no-zstd",
"--format-version",
"1",
"--compress-algo",
"zlib",

As seen in this commit

let cmd = Command::new(self.rcc_executable.as_ref().unwrap())
    .args([
        input_path.to_str().unwrap(),
        "-o",
        output_path.to_str().unwrap(),
        "--name",
        &name,
        "--no-zstd",
        "--format-version",
        "1",
        "--compress-algo",
        "zlib",
    ])

Error: Not building the APK

(Related: #549)

The current qml_minimal example has in CMakeLists.txt:

add_executable(example_qml_minimal cpp/main.cpp)

Use qt_add_executable(), instead of add_executable(). Otherwise, Qt doesn't know what to package as the "application".

After this the app compiled successfully both for the emulator (x86_64) and the Android phone (aarch64).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    ToDo - 0.8

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions