Jeff Ekaka
Jeff Ekaka

Reputation: 75

Failing to configure with CMake while setting up Marble for Android on Linux

I am trying to build Marble, a Qt library for maps and navigation, for Android. For the moment I'd rather go this way than using QtLocation and QML because I am way more comfortable with a C++ interface. To do so I am following this guide : https://community.kde.org/Marble/AndroidCompiling

My specs are the following :

Ok so from there I follow the guide, define the the envrionment variables as needed :

export ANDROID_NDK_ROOT=~/Android/android-ndk-r21
export ANDROID_NDK=$ANDROID_NDK_ROOT
export ANDROID_SDK_ROOT=~/Android/Sdk
export ANT=/usr/bin/ant
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export Qt5_android=/opt/Qt/5.14.1/android
export ECM=~/marble/sources/extra-cmake-modules
export ANDROID_PLATFORM=android-29

And that's when I can't configure with cmake when running the following command from ~/kirigami/build :

cmake ..  -DCMAKE_TOOLCHAIN_FILE=${ECM}/toolchain/Android.cmake -DCMAKE_PREFIX_PATH=${Qt5_android} -DCMAKE_INSTALL_PREFIX=~/marble/export -DECM_DIR=/usr/local/share/ECM/cmake

I get the following error :

-- You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=<targetname> and -DANDROID_APK_DIR=<paths>
-- Android: Targeting API '21' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=<targetname> and -DANDROID_APK_DIR=<paths>
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 9.0.8
-- The CXX compiler identification is Clang 9.0.8
-- Check for working C compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/kali/kirigami/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_be61f/fast && /usr/bin/make -f CMakeFiles/cmTC_be61f.dir/build.make CMakeFiles/cmTC_be61f.dir/build
    make[1]: Entering directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o
    /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/sysroot   -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g -fPIE   -o CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o   -c /home/kali/kirigami/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_be61f
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_be61f.dir/link.txt --verbose=1
    /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/platforms/android-21/arch-arm -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g  -Wl,--fix-cortex-a8  -fPIE -pie -Wl,--gc-sections -Wl,-z,nocopyreloc  CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o  -o cmTC_be61f   -latomic -lm 
    /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
    /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_be61f.dir/build.make:87: cmTC_be61f] Error 1
    make[1]: Leaving directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_be61f/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:6 (project)


-- Configuring incomplete, errors occurred!
See also "/home/kali/kirigami/build/CMakeFiles/CMakeOutput.log".
See also "/home/kali/kirigami/build/CMakeFiles/CMakeError.log".

And here is CMakeOutput.log :

The target system is: Android - 21 - armv7-a
The host system is: Linux - 5.4.0-kali3-amd64 - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
Build flags: 
Id flags:  

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"

The C compiler identification is Clang, found in "/home/kali/kirigami/build/CMakeFiles/3.16.3/CompilerIdC/a.out"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ 
Build flags: 
Id flags:  

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is Clang, found in "/home/kali/kirigami/build/CMakeFiles/3.16.3/CompilerIdCXX/a.out"

And CMakeError.log :

Determining if the C compiler works failed with the following output:
Change Dir: /home/kali/kirigami/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_be61f/fast && /usr/bin/make -f CMakeFiles/cmTC_be61f.dir/build.make CMakeFiles/cmTC_be61f.dir/build
make[1]: Entering directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/sysroot   -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g -fPIE   -o CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o   -c /home/kali/kirigami/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_be61f
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_be61f.dir/link.txt --verbose=1
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --sysroot=/home/kali/Android/android-ndk-r21/platforms/android-21/arch-arm -march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=21 -fexceptions  -g  -Wl,--fix-cortex-a8  -fPIE -pie -Wl,--gc-sections -Wl,-z,nocopyreloc  CMakeFiles/cmTC_be61f.dir/testCCompiler.c.o  -o cmTC_be61f   -latomic -lm 
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
/home/kali/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_be61f.dir/build.make:87: cmTC_be61f] Error 1
make[1]: Leaving directory '/home/kali/kirigami/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_be61f/fast] Error 2

So there seems to be a problem with some linker unable to find libunwind or something like that. I have tried installing libunwind running sudo apt install libunwind-dev as a first guess, but that didn't resolve anything. I am not comfortable enough with cmake, linking etc. to understand and pinpoint the problem, and I can't find any useful information about this issue online. Can you please help me ?

Upvotes: 3

Views: 956

Answers (1)

Jeff Ekaka
Jeff Ekaka

Reputation: 75

Ok so I restarted everything from scracth with a fresh ubuntu 18.04 install. I have set everything up again. A few precisions :

  • I got the latest cmake with snap, apt installed an anterior version which gave some warning or errors.

  • I still went with the latest Qt, Android Sdk and Ndk versions, and I worked with the side by side ndk that can be downloaded through the Sdk manager of Android Studio.

Now the previous error was gone but there still was a problem at this step. I had to download extra-cmake-modules and install it separately in order for cmake to do its job (this is what installed the files in /usr/local/share/ECM). At this point everything is being built without errors. All the more, Qt is able to deploy android applications from the few pre-written android-buildable examples it offers.

However some issues remain.

  • First of all, when trying to deploy the most simple marble app, the latter crashes immediately once installed on my device. I should also mention that I have gone through the whole build/installation process targeting android platform 29, 28 (what my phone is running), and 27, because I have read that beginning from android platform 28, google wishes developer to extensively use its public APIs and in consequence crashes apps trying to call private APIs functions. The error message seems compatible with this explanation. Here is the minimal code :

qmake

TEMPLATE = app

CONFIG += qt

QT += gui \
      widgets


SOURCES += \
  main.cpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target


INCLUDEPATH += /home/dasha/marble/export/include
DEPENDPATH += /home/dasha/marble/export/include


LIBS += /home/dasha/marble/export/lib/libastro_armeabi-v7a.so \
        /home/dasha/marble/export/lib/libKF5Kirigami2_armeabi-v7a.so \
        /home/dasha/marble/export/lib/libmarbledeclarative_armeabi-v7a.so \
        /home/dasha/marble/export/lib/libmarblewidget-qt5_armeabi-v7a.so

main.cpp

#include <QApplication>
#include <marble/MarbleWidget.h>
#include <marble/MarbleDirs.h>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    // Set Paths
    Marble::MarbleDirs::setMarblePluginPath("/home/dasha/marble/export/plugins");
    Marble::MarbleDirs::setMarbleDataPath("home/dasha/marble/export/data");

    // Load Marble using OpenStreetMap in Mercator projection
    Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget;
    mapWidget->setProjection(Marble::Mercator);
    mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");

    mapWidget->setWindowTitle("Hello Marble!");
    mapWidget->show();
    return app.exec();
}

A few lines in each part of the humongous error message

I .example.test_: Late-enabling -Xcheck:jni
W System  : ClassLoader referenced unknown path:
D PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
D OpenGLRenderer: Skia GL Pipeline
I QtCore  : Start
I Qt      : qt started
W .example.test_: Accessing hidden field Landroid/R$styleable;->ViewDrawableStates:[I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->View_background:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->View_padding:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->View_paddingLeft:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->View_paddingTop:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->View_paddingRight:I (light greylist, reflection)
W System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
W System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1864)
W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
W System.err: at android.os.Looper.loop(Looper.java:205)
W System.err: at android.app.ActivityThread.main(ActivityThread.java:6991)
W System.err: at java.lang.reflect.Method.invoke(Native Method)
W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)
W .example.test_: Accessing hidden field Landroid/R$styleable;->SeekBar:[I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->SeekBar_thumb:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->SeekBar_thumbOffset:I (light greylist, reflection)
W .example.test_: Accessing hidden field Lcom/android/internal/R$attr;->switchStyle:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->Switch:[I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->LinearLayout_divider:I (light greylist, reflection)
W .example.test_: Accessing hidden field Landroid/R$styleable;->LinearLayout_showDividers:I (light greylist, reflection)
W .example.test_: Accessing hidden field
Landroid/R$styleable;->LinearLayout_dividerPadding:I (light greylist, reflection)
E AndroidRuntime: FATAL EXCEPTION: qtMainLoopThread
E AndroidRuntime: Process: org.qtproject.example.test_3, PID: 31374
E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libastro_armeabi-v7a.so" not found
E AndroidRuntime: at java.lang.Runtime.load0(Runtime.java:928)
E AndroidRuntime: at java.lang.System.load(System.java:1633)
E AndroidRuntime: at org.qtproject.qt5.android.QtNative$4.run(QtNative.java:275)
E AndroidRuntime: at org.qtproject.qt5.android.QtThread$2.run(QtThread.java:87)
E AndroidRuntime: at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
E AndroidRuntime: at java.lang.Thread.run(Thread.java:764)
I Process : Sending signal. PID: 31374 SIG: 9


"org.qtproject.example.test_3" died.

And it seems that some library hasn't been "exported" and cannot be opened (libastro)... Another remark : adding thses two lines in main.cpp removes all error messages but the app crashes anyway.

Marble::MarbleDirs::setMarblePluginPath("/home/dasha/marble/export/plugins");
Marble::MarbleDirs::setMarbleDataPath("home/dasha/marble/export/data");
  • Second of all, when trying to build an apk as instructed at the end of the guide, I get the following error when running ~/marble/sources/src/apps/marble-maps/create-apk.py --target MarbleMaps.apk ../export from ~/marble/sources :
Cannot find ../export/share/deploy-marble-maps.json. Is ../export really a Marble Android installation?

I don't know why this file hasn't been installed while I can found deploy-behaim.json in the mentioned folder...

I could try installing older version of Qt, Android Sdk and Ndk but I will most likely run into other similar errors anyway, and I have don't have the time to go through that. This installation is too much of a hassle for me, I think I will go with QtLocation etc. for my application, and learn some QML, as it seems to be an easier and a more future-proof method. If you know what is happening however, please feel free to explain what has been going wrong !

Upvotes: 2

Related Questions