问题描述:
最近学习Flutter,在使用图片保存插件 image_gallery_saver ^1.5.0 与 文件路径获取插件 path_provider ^2.0.0 时出现运行失败,错误日志为:
ע: E:\flutter\flutter_windows_2.2.2-stable\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-3.3.0\android\src\main\java\com\baseflow\permissionhandler\PermissionHandlerPlugin.javaʹ�û����ѹ�ʱ�� API��
ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
G:\flutter_aa\startup_flutter\build\app\intermediates\merged_manifests\debug\AndroidManifest.xml:18: AAPT: error: unexpected element <action> found in <manifest>.
* 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 2m 9s
The build failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetifier to solve the incompatibility.
Building plugin image_gallery_saver...
Running Gradle task 'assembleAarRelease'...
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleAarRelease' not found in root project 'image_gallery_saver'. Some candidates are: 'assembleRelease'.
* Try:
Run gradlew tasks to get a list of available tasks. 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
Exception: The plugin image_gallery_saver could not be built due to the issue above.
问题原因:Flutter与AndroidX的兼容问题导致。
解决办法:
步骤一:升级android工程到androidX,官方文档:AndroidX Migration | FlutterHow to migrate existing Flutter projects to AndroidX.https://docs.flutter.dev/development/androidx-migration
步骤二:正常来说升级AndroidX之后,问题解决,但有部分插件需要使用到NDK,所以单独打开使用Android studio单独打开flutter android工程后
File -> Project Structure -> SDK location 选择本地NDK目录
注意:升级到AndroidX,由于实用文档默认 compileSdkVersion与 targetSdkVersion都是28,使用Flutter插件 image_gallery_saver 在Android10以上会出现保存图片失败的问题,建议使用30版本,同时在AndroidManifest.xml 配置requestLegacyExternalStorage = true