khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
98 stars 56 forks source link

Cmake error while building for Android #87

Closed maurovanetti closed 1 year ago

maurovanetti commented 1 year ago

Hello, I'm getting this error while trying to build for Android. It used to work, but I cannot pinpoint easily which dependency or Flutter version triggered the issue, but I've recently switched to Flutter 3.8.0-10.1.pre on the beta channel.

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_zxing:buildCMakeDebug[arm64-v8a]'.
> com.android.ide.common.process.ProcessException: ninja: Entering directory `/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/android/.cxx/Debug/1l4a6h4w/arm64-v8a'
  [1/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/BinaryBitmap.cpp.o
  FAILED: zxing/core/CMakeFiles/ZXing.dir/src/BinaryBitmap.cpp.o 
  /home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -I/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src -Izxing/core -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fno-limit-debug-info  -fPIC -DZXING_BUILD_READERS -DZXING_BUILD_WRITERS -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type -pthread -std=gnu++17 -MD -MT zxing/core/CMakeFiles/ZXing.dir/src/BinaryBitmap.cpp.o -MF zxing/core/CMakeFiles/ZXing.dir/src/BinaryBitmap.cpp.o.d -o zxing/core/CMakeFiles/ZXing.dir/src/BinaryBitmap.cpp.o -c /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.cpp
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.cpp:6:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.h:13:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [2/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/GlobalHistogramBinarizer.cpp.o
  FAILED: zxing/core/CMakeFiles/ZXing.dir/src/GlobalHistogramBinarizer.cpp.o 
  /home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -I/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src -Izxing/core -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fno-limit-debug-info  -fPIC -DZXING_BUILD_READERS -DZXING_BUILD_WRITERS -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type -pthread -std=gnu++17 -MD -MT zxing/core/CMakeFiles/ZXing.dir/src/GlobalHistogramBinarizer.cpp.o -MF zxing/core/CMakeFiles/ZXing.dir/src/GlobalHistogramBinarizer.cpp.o.d -o zxing/core/CMakeFiles/ZXing.dir/src/GlobalHistogramBinarizer.cpp.o -c /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/GlobalHistogramBinarizer.cpp
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/GlobalHistogramBinarizer.cpp:7:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/GlobalHistogramBinarizer.h:9:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.h:13:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [3/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/HybridBinarizer.cpp.o
  FAILED: zxing/core/CMakeFiles/ZXing.dir/src/HybridBinarizer.cpp.o 
  /home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -I/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src -Izxing/core -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fno-limit-debug-info  -fPIC -DZXING_BUILD_READERS -DZXING_BUILD_WRITERS -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type -pthread -std=gnu++17 -MD -MT zxing/core/CMakeFiles/ZXing.dir/src/HybridBinarizer.cpp.o -MF zxing/core/CMakeFiles/ZXing.dir/src/HybridBinarizer.cpp.o.d -o zxing/core/CMakeFiles/ZXing.dir/src/HybridBinarizer.cpp.o -c /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/HybridBinarizer.cpp
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/HybridBinarizer.cpp:7:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/HybridBinarizer.h:9:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/GlobalHistogramBinarizer.h:9:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.h:13:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [4/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/ReedSolomonDecoder.cpp.o
  [5/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/MultiFormatReader.cpp.o
  FAILED: zxing/core/CMakeFiles/ZXing.dir/src/MultiFormatReader.cpp.o 
  /home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -I/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src -Izxing/core -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fno-limit-debug-info  -fPIC -DZXING_BUILD_READERS -DZXING_BUILD_WRITERS -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type -pthread -std=gnu++17 -MD -MT zxing/core/CMakeFiles/ZXing.dir/src/MultiFormatReader.cpp.o -MF zxing/core/CMakeFiles/ZXing.dir/src/MultiFormatReader.cpp.o.d -o zxing/core/CMakeFiles/ZXing.dir/src/MultiFormatReader.cpp.o -c /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/MultiFormatReader.cpp
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/MultiFormatReader.cpp:7:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/MultiFormatReader.h:12:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [6/87] Building CXX object zxing/core/CMakeFiles/ZXing.dir/src/ReadBarcode.cpp.o
  FAILED: zxing/core/CMakeFiles/ZXing.dir/src/ReadBarcode.cpp.o 
  /home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/mauro/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -I/home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src -Izxing/core -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fno-limit-debug-info  -fPIC -DZXING_BUILD_READERS -DZXING_BUILD_WRITERS -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type -pthread -std=gnu++17 -MD -MT zxing/core/CMakeFiles/ZXing.dir/src/ReadBarcode.cpp.o -MF zxing/core/CMakeFiles/ZXing.dir/src/ReadBarcode.cpp.o.d -o zxing/core/CMakeFiles/ZXing.dir/src/ReadBarcode.cpp.o -c /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/ReadBarcode.cpp
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/ReadBarcode.cpp:9:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/GlobalHistogramBinarizer.h:9:
  In file included from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/src/zxing/core/src/BinaryBitmap.h:13:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  ninja: build stopped: subcommand failed.

  C++ build system [build] failed while executing:
      /home/mauro/Android/Sdk/cmake/3.18.1/bin/ninja \
        -C \
        /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/android/.cxx/Debug/1l4a6h4w/arm64-v8a \
        flutter_zxing
    from /home/mauro/.pub-cache/hosted/pub.dev/flutter_zxing-1.1.1/android

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 13s
Exception: Gradle task assembleDebug failed with exit code 1
maurovanetti commented 1 year ago

The same issue occurs with Flutter 3.7.7 on the master channel.

Alecsplus commented 1 year ago

I have the same problem

khoren93 commented 1 year ago

Hi @maurovanetti @Alecsplus

I'm unable to reproduce this issue on my end. To troubleshoot this problem, I recommend switching to the Flutter stable channel, updating to the latest version of the project, and then updating the zxing submodule using the following command: git submodule update --remote. After doing so, please attempt to reproduce the issue again.

neo-hornberger commented 1 year ago

I had the same problem yesterday. (snap version of Flutter 3.7.7 on the stable channel)

I looked into it, and the error trace points to the standard library file memory.

/snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
  const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.

So, it seems like the provided/bundled version of GCC/C++ (here, version 9.*.*) in the snap build is broken/outdated/not compatible.

"Solving" the "issue" was as simple as manually installing Flutter from their GitHub repo. Now Flutter will use my system-wide installed GCC/C++ version. (In my case, version 11.3.0)

maurovanetti commented 1 year ago

"Solving" the "issue" was as simple as manually installing Flutter from their GitHub repo. Now Flutter will use my system-wide installed GCC/C++ version. (In my case, version 11.3.0)

Thank you! This fixed the issue.