如何在Kivy/Buildozer安卓项目中添加.aar文件?构建报错求助
问题:Kivy项目添加onnxruntime.aar构建APK失败
项目结构
├── buildozer.spec ├── dress.jpg ├── libs │ └── onnxruntime.aar ├── log.txt ├── main.py ├── __pycache__ │ ├── temp3.cpython-310.pyc │ ├── temp3.cpython-39.pyc │ ├── tflite_models2.cpython-310.pyc │ ├── tflite_models2.cpython-39.pyc │ └── tflite_models.cpython-39.pyc ├── temp3.py └── tflite_models2.py
buildozer.spec相关配置
[app] # (str) Title of your application title = Test_onnx_image # (str) Package name package.name = test_onnx # (str) Package domain (needed for android/ios packaging) package.domain = org.test # (str) Source code where the main.py live source.dir = . # (list) Source files to include (let empty to include all the files) source.include_exts = py,png,jpg,kv,atlas,aar # (list) Application requirements # comma separated e.g. requirements = sqlite3,kivy requirements = python3,kivy==2.3.1,numpy,filetype,plyer,pillow,pyjnius android.requirements.source.pyjnius = https://github.com/kivy/pyjnius/archive/refs/heads/master.zip # (list) Android AAR archives to add (currently works only with sdl2_gradle # bootstrap) android.add_aars = android.add_aars = libs/onnxruntime.aar
构建错误信息
执行buildozer -v android debug后出现以下错误:
[INFO]: Detected highest available build tools version to be 36.1.0 [DEBUG]: -> running gradlew clean assembleDebug [DEBUG]: > Task :checkDebugAarMetadata FAILED [DEBUG]: [DEBUG]: FAILURE: Build failed with an exception. [DEBUG]: [DEBUG]: * What went wrong: [DEBUG]: Execution failed for task ':checkDebugAarMetadata'. [DEBUG]: > Could not resolve all files for configuration':debugRuntimeClasspath'. [DEBUG]: > Could not find :onnxruntime:. [DEBUG]: Required by: [DEBUG]: project : [DEBUG]: [DEBUG]: * Try: [DEBUG]: > Run with --stacktrace option to get the stack trace. [DEBUG]: > Run with --info or --debug option to get more log output. [DEBUG]: > Run with --scan to get full insights. [DEBUG]: [DEBUG]: * Get more help at https://help.gradle.org/ [DEBUG]: [DEBUG]: Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. [DEBUG]: [DEBUG]: You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. [DEBUG]: [DEBUG]: See https://docs.gradle.org/8.0.2/userguide/command_line_interface.html#sec:command_line_warnings
解决方案
修正android.add_aars配置项
你的配置里重复写了android.add_aars =,导致Gradle无法正确识别AAR文件路径。把该行修改为:android.add_aars = libs/onnxruntime.aar确认使用sdl2_gradle bootstrap
注释里明确说明android.add_aars仅对sdl2_gradlebootstrap生效,所以需要在[app]section中添加或修改:android.bootstrap = sdl2_gradle如果原本有
android.bootstrap = sdl2,替换成sdl2_gradle即可。验证AAR文件完整性
确保libs/onnxruntime.aar文件存在且未损坏,可以尝试重新下载该文件,避免因文件损坏导致Gradle无法解析。
内容的提问来源于stack exchange,提问作者Noob_Testautomation
相关产品推荐
相关产品推荐

