cloudacy / native_exif

A simple EXIF metadata reader/writer for Flutter.
MIT License
16 stars 14 forks source link

No Implementation Found For Method initPath #15

Open lornpavan opened 1 year ago

lornpavan commented 1 year ago

When I try to use the first command: final exif = await Exif.fromPath(picture!.path); I get the following error: E/flutter (10499): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method initPath on channel native_exif) I have tried to run flutter clean and flutter pub get to no avail.

gotneb commented 1 year ago

I'm facing the same issue.

d-kuen commented 1 year ago

It sounds like a project misconfiguration.

You may want to check out https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects#full-flutter-app-migration (most importantly the GeneratedPluginRegistrant parts) or compare your iOS AppDelegate.[m/swift] and android MainActivity.[java/kt] with the example app of this plugin.

Also you may want to run flutter clean and restart your app.

SG-XM commented 1 year ago

我也有同样的问题在android13上,因为29之后无法读取gps信息https://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns#LATITUDE,所以我需要读取图片的exif

SG-XM commented 1 year ago

It sounds like a project misconfiguration.

You may want to check out https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects#full-flutter-app-migration (most importantly the GeneratedPluginRegistrant parts) or compare your iOS AppDelegate.[m/swift] and android MainActivity.[java/kt] with the example app of this plugin.

Also you may want to run flutter clean and restart your app.

flutter clean之后也没有用


import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.Log;

import io.flutter.embedding.engine.FlutterEngine;

/**
 * Generated file. Do not edit.
 * This file is generated by the Flutter tool based on the
 * plugins that support the Android platform.
 */
@Keep
public final class GeneratedPluginRegistrant {
  private static final String TAG = "GeneratedPluginRegistrant";
  public static void registerWith(@NonNull FlutterEngine flutterEngine) {
    try {
      flutterEngine.getPlugins().add(new me.yohom.amap_core_fluttify.AmapCoreFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin amap_core_fluttify, me.yohom.amap_core_fluttify.AmapCoreFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new me.yohom.amap_location_fluttify.AmapLocationFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin amap_location_fluttify, me.yohom.amap_location_fluttify.AmapLocationFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new me.yohom.amap_map_fluttify.AmapMapFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin amap_map_fluttify, me.yohom.amap_map_fluttify.AmapMapFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new me.yohom.amap_search_fluttify.AmapSearchFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin amap_search_fluttify, me.yohom.amap_search_fluttify.AmapSearchFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new me.yohom.core_location_fluttify.CoreLocationFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin core_location_fluttify, me.yohom.core_location_fluttify.CoreLocationFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new me.yohom.foundation_fluttify.FoundationFluttifyPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin foundation_fluttify, me.yohom.foundation_fluttify.FoundationFluttifyPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new com.cloudacy.native_exif.NativeExifPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin native_exif, com.cloudacy.native_exif.NativeExifPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new com.baseflow.permissionhandler.PermissionHandlerPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin permission_handler, com.baseflow.permissionhandler.PermissionHandlerPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new com.fluttercandies.photo_manager.PhotoManagerPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin photo_manager, com.fluttercandies.photo_manager.PhotoManagerPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin shared_preferences_android, io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin url_launcher_android, io.flutter.plugins.urllauncher.UrlLauncherPlugin", e);
    }
  }
}

自动生成的文件中也看着没有问题

jackxuechen commented 10 months ago

This problem is caused by writing to a read-only file, you should read the file and write into the app sandbox directory. The following code works just fine.

var imgData = imgByteData.buffer.asUint8List(); File? tempFile = await Utils.saveFileToTemp(imgData, "tmp_image.jpg"); if (tempFile == null) { return; } var tempFilePath = tempFile.path; try { final exif = await Exif.fromPath(tempFilePath); await exif.writeAttribute("UserComment", "123456"); final userComment = await exif.getAttribute("UserComment"); LogUtil.v("userComment: $userComment", tag: 'saveToLocal'); await exif.close(); } catch (e) { LogUtil.e("err: $e", tag: 'saveToLocal'); }

static Future<File?> saveFileToTemp(Uint8List bytes, String fileName) async { try { final String tempPath = (await getTemporaryDirectory()).path; final String filePath = tempPath + '/' + fileName; final File targetFile = File(filePath); if (await targetFile.exists()) { await targetFile.delete(); } return await targetFile.writeAsBytes(bytes); } catch (e) { print('e:$e'); } }

darielkurt commented 2 months ago

@jackxuechen What are the files that are read-only? we only write on captured images, some works, some don't. My hunch is it depends on the device?