以module形式导入library出错:Error:A problem occurred configuring project ':library'.

本文解决在Android Studio中导入含NDK的第三方library时遇到的编译错误,涉及NDK安装、配置及特定ABI工具链缺失问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直入主题:在我项目开发时,需要导入第三方的library,在Android studio中以module形式导入到项目中,编译运行时,报了如下的错误:


 

经过查找,产生这个问题的原因有很多,后来发现,我的问题是因为导入library的build.gradle中有这样一段:


 

这个(红框框起来的代码)是引用NDK中的ABI文件,这时我发现我的Android studio中没有安装NDK。于是乎安装NDK:


安装NDK


点击Android studio中的这个按钮

打开此页面,如果本地下载有解压好的NDK文档,可以自定义安装(按图中2选择);如果没有,就直接在Android studio中安装(按图中1选择),我是按中1步骤来的,如果想按图中2来,点击我下载对应版本NDK,(前面不行,再点我)进行自定义配置

 

然后就出现下面的下载页面,这时候就可以静静的喝咖啡,等最后点击finish就行了


安装完会自动编译,这个时候,你应该还能遇到一个这样的问题,直接盘(点击)它就行了


如果一切OK,就可以快乐敲代码了,但是我却遇到新的问题了:Error:No toolchains found in the NDK toolchains folder for ABI with prefix:

 

解决:Error:No toolchains found in the NDK toolchains folder for ABI with prefix:


吓的我赶紧找度娘,发现早已有网友们为我踩过雷了,接下来直接排雷,这个问题有两种解决方式,我先贴上链接:
方法一: https://blog.youkuaiyun.com/qq_24118527/article/details/82867864

方法二: https://blog.youkuaiyun.com/vocanicy/article/details/83004626

结论:第一种方法讲的比较详细,是因为缺少文件导致的;第二种方法很简单,是因为Android studio版本问题,配置下就好了,如果项目中使用的是ndk_17(包括ndk_17)以上的,就直接使用第二种方法,否则,看第一种方法就行。
注意:我没试ndk_17好使不,如果你用的是ndk_17,你就自测下,为什么这么说,接着往下看☟。

原因:我把ndk_15——ndk_19都下载下来对比了一下,ndk_17(包括ndk_17)以下都有我们需要的那个文件夹(mips64el-linux-android-4.9),而我上面下载的是ndk_19,所以我也没找到该文件

 

建议:经过查看NDK修订历史记录,可以看到下面的话,所以你使用的是ndk_17的话,上面的结论提到的 “ndk_17(包括ndk_17)以上的,就直接使用第二种方法” ,就需要你自行测17版本了,建议将自己项目中的ndk更新为最新版本,或者大于17版本,直接使用方法二。

 

好了,当你看到这儿,说明你已经解决了该问题(give me five !),如果还有什么问题,欢迎留言讨论。

flutter安装image_gallery_saver后运行报错,怎么解决 FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Failed to query the value of property 'buildFlowServiceProperty'. > Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@4e390559 of type BuildFlowService.Parameters > A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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 1s Running Gradle task 'assembleDebug'... 2,434ms Error: Gradle task assembleDebug failed with exit code 1 PS D:\develop\Flutter\ProjectTest\words_myths> flutter run Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Launching lib\main.dart on M2007J22C in debug mode... Support for Android x86 targets will be removed in the next stable release after 3.27. See https://github.com/flutter/flutter/issues/157543 for details. FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Failed to query the value of property 'buildFlowServiceProperty'. > Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@312973b2 of type BuildFlowService.Parameters > A problem occurred configuring project ':image_gallery_saver'. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant. * 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 1s Running Gradle task 'assembleDebug'... 2,546ms Error: Gradle task assembleDebug failed with exit code 1 PS D:\develop\Flutter\ProjectTest\words_myths>
最新发布
06-22
cessfully installed Mastodon.py-2.0.1 blurhash-1.1.4 boost-0.1 certifi-2025.4.26 charset_normalizer-3.4.2 decorator-5.2.1 greenlet-3.2.3 idna-3.10 python-dateutil-2.9.0.post0 python-magic-bin-0.4.14 requests-2.32.4 six-1.17.0 sqlalchemy-2.0.41 typing-extensions-4.14.0 urllib3-2.4.0 [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> pip install dlib -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting dlib Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/f4/f8949b18ec1df2ef05fc2ea1d1dd82ff2d050b8704b7d0d088017315c221/dlib-20.0.0.tar.gz (3.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 4.9 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: dlib Building wheel for dlib (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for dlib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [48 lines of output] running bdist_wheel running build running build_ext Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\OCR\AW\.venv1\Scripts\cmake.exe\__main__.py", line 4, in <module> ModuleNotFoundError: No module named 'cmake' ================================================================================ ================================================================================ ================================================================================ CMake is not installed on your system! Or it is possible some broken copy of cmake is installed on your system. It is unfortunately very common for python package managers to include broken copies of cmake. So if the error above this refers to some file path to a cmake file inside a python or anaconda or miniconda path then you should delete that broken copy of cmake from your computer. Instead, please get an official copy of cmake from one of these known good sources of an official cmake: - cmake.org (this is how windows users should get cmake) - apt install cmake (for Ubuntu or Debian based systems) - yum install cmake (for Redhat or CenOS based systems) On a linux machine you can run `which cmake` to see what cmake you are actually using. If it tells you it's some cmake from any kind of python packager delete it and install an official cmake. More generally, cmake is not installed if when you open a terminal window and type cmake --version you get an error. So you can use that as a very basic test to see if you have cmake installed. That is, if cmake --version doesn't run from the same terminal window from which you are reading this error message, then you have not installed cmake. Windows users should take note that they need to tell the cmake installer to add cmake to their PATH. Since you can't run commands that are not in your PATH. This is how the PATH works on Linux as well, but failing to add cmake to the PATH is a particularly common problem on windows and rarely a problem on Linux. ================================================================================ ================================================================================ ================================================================================ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> import sys import : 无法将“import”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + import sys + ~~~~~~ + CategoryInfo : ObjectNotFound: (import:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException (.venv1) PS D:\OCR\AW> print(sys.executable) # 应显示自定义路径 sys.executable : 无法将“sys.executable”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 7 + print(sys.executable) # 应显示自定义路径 + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (sys.executable:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException (.venv1) PS D:\OCR\AW> pip uninstall cmake Found existing installation: cmake 4.0.2 Uninstalling cmake-4.0.2: Would remove: d:\ocr\aw\.venv1\lib\site-packages\cmake-4.0.2.dist-info\* d:\ocr\aw\.venv1\lib\site-packages\cmake\* d:\ocr\aw\.venv1\scripts\ccmake.exe d:\ocr\aw\.venv1\scripts\cmake.exe d:\ocr\aw\.venv1\scripts\cpack.exe d:\ocr\aw\.venv1\scripts\ctest.exe Proceed (Y/n)? cmake --version # 应显示 ≥3.5 的版本 Your response ('cmake --version # 应显示 ≥3.5 的版本') was not one of the expected responses: y, n, Proceed (Y/n)? Y Successfully uninstalled cmake-4.0.2 (.venv1) PS D:\OCR\AW> cmake --version # 应显示 ≥3.5 的版本 cmake version 4.0.2 CMake suite maintained and supported by Kitware (kitware.com/cmake). (.venv1) PS D:\OCR\AW> $env:VSCMD_ARG_TGT_ARCH = 'x64' (.venv1) PS D:\OCR\AW> $env:Path += ";C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64" (.venv1) PS D:\OCR\AW> # 使用清华镜像安装 (.venv1) PS D:\OCR\AW> pip install dlib==19.24.0 -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting dlib==19.24.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e5/3b/7a8522a5c2ef6ff6252e46b0788b3d2c2280198c49d6ecf3b576b171045f/dlib-19.24.0.tar.gz (3.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 6.0 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done Building wheels for collected packages: dlib Building wheel for dlib (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [60 lines of output] running bdist_wheel running build running build_py running build_ext C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\setup.py:129: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. if LooseVersion(cmake_version) < '3.1.0': Building extension for Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] Invoking CMake setup: 'cmake C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\d lib_0adc76f556db44bd8f9f76c52f05b10a\build\lib.win-amd64-cpython-39 -DPYTHON_EXECUTABLE=D:\OCR\AW\.venv1\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\build\lib.win-amd64-cpython-39 -A x64' -- Building for: Visual Studio 17 2022 CMake Error at CMakeLists.txt:2 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. -- Configuring incomplete, errors occurred! Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\setup.py", line 222, in <module> setup( File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\__init__.py", line 103, in setup return distutils.core.setup(**attrs) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\core.py", line 185, in setup return run_commands(dist) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands dist.run_commands() File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands self.run_command(cmd) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "D:\OCR\AW\.venv1\lib\site-packages\wheel\bdist_wheel.py", line 364, in run self.run_command("build") File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command self.distribution.run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run self.run_command(cmd_name) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command self.distribution.run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\setup.py", line 134, in run self.build_extension(ext) File "C:\Users\Admin\AppData\Local\Temp\pip-install-ax2yzknp\dlib_0adc76f556db44bd8f9f76c52f05b10a\setup.py", line 171, in build_extension subprocess.check_call(cmake_setup, cwd=build_folder) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 373, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-ax2yzknp\\dlib_0adc76f556db44bd8f9f76c52f05b10a\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Admin\\AppD ata\\Local\\Temp\\pip-install-ax2yzknp\\dlib_0adc76f556db44bd8f9f76c52f05b10a\\build\\lib.win-amd64-cpython-39', '-DPYTHON_EXECUTABLE=D:\\OCR\\AW\\.venv1\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-ax2yzknp\\dlib_0adc76f556db44bd8f9f76c52f05b10a\\build\\lib.win-amd64-cpython-39', '-A', 'x64']' returned non-zero exit status 1. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Running setup.py clean for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> # 直接安装预编译的 whl 文件(需匹配 Python 版本) (.venv1) PS D:\OCR\AW> pip install https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0697c76b04dc5c3b0d6ad5f8c1b092bd8e9a6/dlib-19.24.0-cp39-cp39-win_amd64.whl Collecting dlib==19.24.0 ERROR: HTTP error 404 while getting https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0697c76b04dc5c3b0d6ad5f8c1b092bd8e9a6/dlib-19.24.0-cp39-cp39-win_amd64.whl ERROR: Could not install requirement dlib==19.24.0 from https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0697c76b04dc5c3b0d6ad5f8c1b092bd8e9a6/dlib-19.24.0-cp39-cp39-win_amd64.whl because of HTTP error 404 Clien t Error: Not Found for url: https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0697c76b04dc5c3b0d6ad5f8c1b092bd8e9a6/dlib-19.24.0-cp39-cp39-win_amd64.whl for URL https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0697c76b04dc5c3b0d6ad5f8c1b092bd8e9a6/dlib-19.24.0-cp39-cp39-win_amd64.whl [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW>
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值