Samoy / image_save

Save image to album or sandbox
https://pub.dev/packages/image_save
MIT License
23 stars 27 forks source link

Fix the failure of saving pictures in Android 10 #14

Open fengdeyingzi opened 3 years ago

nekomiyaxneko commented 3 years ago

您好,我使用您修改后的插件,在运行时出现如下报错信息

C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:98: ����: �����Build������
        if(Build.VERSION.SDK_INT >= 29){
                ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:99: ����: �Ҳ�������
            String mimeType = URLConnection.getFileNameMap().getContentTypeFor(imageName);
                              ^
  ����:   ���� URLConnection
  �: �� ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:101: ����: �Ҳ�������
            ContentValues values = new ContentValues();
            ^
  ����:   �� ContentValues
  �: �� ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:101: ����: �Ҳ�������
            ContentValues values = new ContentValues();
                                       ^
  ����:   �� ContentValues
  �: �� ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:102: ����: �����MediaStore������
            values.put(MediaStore.MediaColumns.DISPLAY_NAME,fileName);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:103: ����: �����MediaStore������
            values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:104: ����: �����MediaStore������
            values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:105: ����: �Ҳ�������
            ContentResolver contentResolver = context.getContentResolver();
            ^
  ����:   �� ContentResolver
  �: �� ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:106: ����: �����MediaStore.Images������
            Uri uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                                                              ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:111: ����: �Ҳ�������
                OutputStream out = contentResolver.openOutputStream(uri);
                ^
  ����:   �� OutputStream
  �: �� ImageSavePlugin
10 ������

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':image_save:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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 38s
Exception: Gradle task assembleDebug failed with exit code 1

请问您是否成功运行您修改后的代码

fengdeyingzi commented 3 years ago

APP已经发布,当然有成功运行喽,你看看你是怎么调用它的 @nekomiyaxneko #14

nekomiyaxneko commented 3 years ago

我是按照原作者文档给的方法调用的。这个报错是在编译的时候出现的。我想请问一下您使用的compileSdkVersion和targetSdkVersion是多少?

fengdeyingzi commented 3 years ago

我是按照原作者文档给的方法调用的。这个报错是在编译的时候出现的。我想请问一下您使用的compileSdkVersion和targetSdkVersion是多少?

29 @nekomiyaxneko

nekomiyaxneko commented 3 years ago

我修复了Gradle的乱码之后,看到报错信息如下:

C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:98: 错误: 程序包Build不存在
        if(Build.VERSION.SDK_INT >= 29){
                ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:99: 错误: 找不到符号
            String mimeType = URLConnection.getFileNameMap().getContentTypeFor(imageName);
                              ^
  符号:   变量 URLConnection
  位置: 类 ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:101: 错误: 找不到符号
            ContentValues values = new ContentValues();
            ^
  符号:   类 ContentValues
  位置: 类 ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:101: 错误: 找不到符号
            ContentValues values = new ContentValues();
                                       ^
  符号:   类 ContentValues
  位置: 类 ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:102: 错误: 程序包MediaStore不存在
            values.put(MediaStore.MediaColumns.DISPLAY_NAME,fileName);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:103: 错误: 程序包MediaStore不存在
            values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:104: 错误: 程序包MediaStore不存在
            values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM);
                                 ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:105: 错误: 找不到符号
            ContentResolver contentResolver = context.getContentResolver();
            ^
  符号:   类 ContentResolver
  位置: 类 ImageSavePlugin
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:106: 错误: 程序包MediaStore.Images不存在
            Uri uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                                                              ^
C:\src\flutter\.pub-cache\git\image_save-35b7b9a9086860c94daef7123e8d9c5111a2bbf9\android\src\main\java\com\samoy\image_save\ImageSavePlugin.java:111: 错误: 找不到符号
                OutputStream out = contentResolver.openOutputStream(uri);
                ^
  符号:   类 OutputStream
  位置: 类 ImageSavePlugin
10 个错误

FAILURE: Build failed with an exception.

然后我查询并导入这些报错的包

import android.content.ContentValues;
import android.content.ContentResolver;
import android.provider.MediaStore;
import android.os.Build;
import java.io.OutputStream;
import java.net.URLConnection;

并修改了插件android/目录下的build.gradlecompileSdkVersion 28改为compileSdkVersion 29

最后终于成功编译了 [大哭]