Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Module in Android cannot use flutter package #7452

Closed
CaoGiaHieu-dev opened this issue May 24, 2024 · 0 comments
Closed

Flutter Module in Android cannot use flutter package #7452

CaoGiaHieu-dev opened this issue May 24, 2024 · 0 comments

Comments

@CaoGiaHieu-dev
Copy link

Im create a flutter module using package google_mlkit_face_detector and got this message
MissingPluginException(No implementation found for method vision#startFaceDetector on channel google_mlkit_face_detector)
2024-05-24 16:46:24.157 15237-15962 flutter com.example.example_android I #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)

#1 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:520:35)

#2 FaceDetector.processImage (package:google_mlkit_face_detection/src/face_detector.dart:23:20)

#3 LivenessProvider._processImage (package:ekyc_module_v2/core/providers/liveness_provider.dart:405:19)

#4 LivenessProvider.processCameraImage (package:ekyc_module_v2/core/providers/liveness_provider.dart:189:5)

Steps to Reproduce

1 : flutter create -t module --org com.example flutter_module
2: import google_mlkit_face_detector package and some feature
3: build aar via this command flutter build aar --no-tree-shake-icons
4: create a new android project and follow document
5: Implement this code to start a flutter module in android

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val button = findViewById<Button>(R.id.button)
        button.setOnClickListener {
            onStartEkyc(it)
        }
    }

    private fun onStartEkyc(view: View) {
        val EngineID = "1"
        val flutterEngine = FlutterEngine(this)
        flutterEngine.dartExecutor.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault())
        FlutterEngineCache.getInstance().put(EngineID, flutterEngine)

        val channel = MethodChannel(flutterEngine.dartExecutor, "com.ekyC/mainChannel")

        var json = readJSONFromAsset()
        val config = JSONObject(json).toMap()
        channel.invokeMethod("init", config);


        val responseChannel =
            MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.ekyC/mainChannel")
        responseChannel.setMethodCallHandler { call, result ->
            when (call.method) {
                "exceptionCallBack" -> Log.d("exceptionCallBack", call.arguments.toString());
                "onCancel" -> flutterEngine.destroy();
            }
        }

        startActivity(FlutterActivity.withCachedEngine(EngineID).build(this));


    }

    fun readJSONFromAsset(): String? {
        var json: String? = null
        try {
            val inputStream: InputStream = application.assets.open("example.json")
            json = inputStream.bufferedReader().use { it.readText() }
        } catch (ex: Exception) {
            ex.printStackTrace()
            return null
        }
        return json
    }

    fun JSONObject.toMap(): Map<String, *> = keys().asSequence().associateWith {
        when (val value = this[it]) {
            is JSONArray -> {
                val map = (0 until value.length()).associate { Pair(it.toString(), value[it]) }
                JSONObject(map).toMap().values.toList()
            }

            is JSONObject -> value.toMap()
            JSONObject.NULL -> null
            else -> value
        }
    }
}

This issue happen in other package like path_provider , etc

Version info

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-x64, locale vi)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.89.1)
[✓] Connected device (1 available)
[✓] Network resources

• No issues found!

@CaoGiaHieu-dev CaoGiaHieu-dev closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant