如何解决Flutter构建时':rive_common:buildCMakeDebug[arm64-v8a]'任务失败问题
解决Flutter构建时rive_common的uintptr_t类型转换错误
构建Flutter应用时遇到以下编译错误,核心问题是指针转换为更小的uintptr_t类型时丢失信息,导致C++编译失败,进而触发Gradle任务执行异常:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':rive_common:buildCMakeDebug[arm64-v8a]'. > com.android.ide.common.process.ProcessException: ninja: Entering directory `/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/android/.cxx/Debug/13194d4d/arm64-v8a' [1/64] Building CXX object CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp.o FAILED: CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp.o /home/mcrops/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --sysroot=/home/mcrops/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Drive_text_EXPORTS -I../../../../../ios/harfbuzz/src -I../../../../../ios/rive-cpp/skia/renderer/include -I../../../../../ios/rive-cpp/include -I../../../../../ios/SheenBidi/Headers -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -DWITH_RIVE_TEXT -DHAVE_OT -DHB_NO_FALLBACK_SHAPE -DHB_NO_WIN1256 -std=c++11 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp.o -MF CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp.o.d -o CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp.o -c /home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp In file included from /home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/rive_counter.cpp:5: In file included from ../../../../../ios/rive-cpp/include/rive/rive_counter.hpp:8: In file included from ../../../../../ios/rive-cpp/include/rive/rive_types.hpp: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. [2/64] Building CXX object CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/text/line_breaker.cpp.o FAILED: CMakeFiles/rive_text.dir/home/mcrops/.pub-cache/hosted/pub.dev/rive_common-0.2.7/ios/rive-cpp/src/text/line_breaker.cpp.o * 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 28s Exception: Gradle task assembleDebug failed with exit code 1
可能的解决方法
1. 更新rive_common包
当前使用的rive_common版本为0.2.7,该版本存在已知的编译兼容性问题。打开项目的pubspec.yaml文件,将依赖的rive或rive_common更新至最新版本:
dependencies: rive: ^latest_version # 替换为实际最新版本号
执行flutter pub get更新依赖后重新构建项目。
2. 调整Android NDK版本
错误中使用的NDK版本为25.1.8937393,部分旧版C++代码与该版本存在兼容性冲突。尝试切换至更稳定的NDK版本(如23.x或24.x):
- 打开
android/app/build.gradle文件,在android块中指定NDK版本:
android { ndkVersion "23.2.8568313" // 替换为兼容的NDK版本 // 其他配置项... }
- 若使用Android Studio,可通过SDK Manager安装指定版本的NDK后选择使用。
3. 修改C++编译标准
当前编译使用C11,切换至更高版本的C标准(如C++17)可解决类型转换问题:
- 在项目的
android/build.gradle中添加全局C++标准配置:
subprojects { afterEvaluate { project -> if (project.hasProperty('android')) { android { defaultConfig { externalNativeBuild { cmake { cppFlags "-std=c++17" } } } } } } }
内容的提问来源于stack exchange,提问作者BANADDA MUBARAKA
相关产品推荐
相关产品推荐

