Skip to content

Linker error when building for Android #7

@JeroenvdV

Description

@JeroenvdV

Not sure what to try, let me know how I can help. I cloned the repository, and am running flutter build apk -v. Then the error is:

e: /home/jeroen/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common/2.6.1/10f354fdb64868baecd67128560c5a0d6312c495/lifecycle-common-2.6.1.jar!/META-INF/lifecycle-common.kotlin_module: Module was
compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

To fix this, I changed ext.kotlin_version to 1.8.10 from 1.6.10.

Note, also gradle was upgraded automatically:

Upgrading build.gradle
Conflict detected between Android Studio Java version and Gradle version, upgrading Gradle version from 6.7 to 7.6.1.
Upgrading gradle-wrapper.properties

The next error is:

[        ] Execution failed for task ':app:processReleaseMainManifest'.
[        ] > Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @76cbb5e7

To fix, I changed android/gradle.properties to:

org.gradle.jvmargs=-Xmx1536M \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.useAndroidX=true
android.enableJetifier=true

Finally, the linker error I can't solve is:

        ] Execution failed for task ':app:externalNativeBuildRelease'.
[        ] > Build command failed.
[        ]   Error while executing process /home/jeroen/Android/Sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /home/jeroen/Files/Ball/android/app/.cxx/cmake/release/armeabi-v7a OpenCV_ffi}
[        ]   ninja: Entering directory `/home/jeroen/Files/Ball/android/app/.cxx/cmake/release/armeabi-v7a'
[        ]   [1/2] Building CXX object CMakeFiles/OpenCV_ffi.dir/home/jeroen/Files/Ball/lib/opencv-cpp/main.cpp.o
[        ]   [2/2] Linking CXX shared library /home/jeroen/Files/Ball/build/app/intermediates/cmake/release/obj/armeabi-v7a/libOpenCV_ffi.so
[        ]   FAILED: /home/jeroen/Files/Ball/build/app/intermediates/cmake/release/obj/armeabi-v7a/libOpenCV_ffi.so 
[        ]   : && /home/jeroen/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21
--gcc-toolchain=/home/jeroen/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/jeroen/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections
-ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -std=c++17 -Oz -DNDEBUG
-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared
-Wl,-soname,libOpenCV_ffi.so -o /home/jeroen/Files/Ball/build/app/intermediates/cmake/release/obj/armeabi-v7a/libOpenCV_ffi.so CMakeFiles/OpenCV_ffi.dir/home/jeroen/Files/Ball/lib/opencv-cpp/main.cpp.o
../../../../../src/main/jniLibs/armeabi-v7a/libopencv_java4.so -latomic -lm && :
[   +2 ms]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:6: error: undefined reference to 'cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:6: error: undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:9: error: undefined reference to 'cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&,
std::vector<int, std::allocator<int> > const&)'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:9: error: undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:9: error: undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/gaussian.cpp:6: error: undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/image_ffi.cpp:11: error: undefined reference to 'cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
[        ]   /home/jeroen/Files/Ball/lib/opencv-cpp/image_ffi.cpp:15: error: undefined reference to 'cv::imencode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&,
std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
[        ]   /snap/flutter/current/usr/include/c++/9/bits/basic_string.tcc:219: error: undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned
int)'
[        ]   /snap/flutter/current/usr/include/c++/9/bits/basic_string.tcc:212: error: undefined reference to 'std::__throw_logic_error(char const*)'
[        ]   /snap/flutter/current/usr/include/c++/9/bits/stl_vector.h:1767: error: undefined reference to 'std::__throw_length_error(char const*)'
[        ]   /snap/flutter/current/usr/include/c++/9/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
[        ]   /snap/flutter/current/usr/include/c++/9/iostream:0: error: undefined reference to 'std::ios_base::Init::~Init()'
[        ]   clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[        ]   ninja: build stopped: subcommand failed.

Does this have to do with an incompatibility between C++11 and C++17? Note how the android/app/build.gradle file specifies cppFlags '-frtti -fexceptions -std=c++17', which differs from the version on the website linked from the README.md where it specifiecs c++11. Changing this results in a different error though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions