Context :
I would like to create a FFI Plugin Flutter and I follow this official google tuto for doing that : Using FFI in a Flutter plugin
Technical info :
- Windows 11
- Flutter 3.19.1
- clang 16.0.4 (LLVM installed and provided into PATH system)
return error after this command :
- cd example
- flutter run -d windows
error :
Launching libmain.dart on Windows in debug mode…
CUSTOMBUILD :
error : Couldn’t resolve the package ‘ffi’ in ‘package:ffi/ffi.dart’.
[C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64flutterflutter_assemble.vcxproj]
../lib/ffigen_app.dart(3,8): error G832450DD: Not found:
‘package:ffi/ffi.dart’
[C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64flutterflutter_assemble.vcxproj]
../lib/ffigen_app.dart(42,9): error GC9768DF9: Undefined name
‘malloc’.
[C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64flutterflutter_assemble.vcxproj]
../lib/ffigen_app.dart(31,29): error GE5CFE876: The method
‘toNativeUtf8’ isn’t defined for the class ‘String’.
[C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64flutterflutter_assemble.vcxproj]
C:Program FilesMicrosoft Visual
Studio2022CommunityMSBuildMicrosoftVCv170Microsoft.CppCommon.targets(254,5):
error MSB8066: la build personnalis�e de
‘C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64CMakeFiles2133b62afd0dee54b370c45418a7c00fflutter_windows.dll.rule;C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64CMakeFiles6286011a556565967b6192c6afee09a7flutter_assemble.rule’
s’est arr�t�e. Code�1.
[C:PROJECTANDROIDStudioffigen_appexamplebuildwindowsx64flutterflutter_assemble.vcxproj]
Building Windows application…
7,5s Error: Build process failed.
Explain :
I follow all the tuto code and copy/paste into my project without another personnal change. also the 3 DuckTape file are copied into src/. For convenience I don’t duplicate code example that exist into the link shared begin. But share the main.dart entry file for example test application flutter :
import 'package:ffigen_app/ffigen_app.dart';
import 'package:flutter/material.dart';
const String jsCode = '1+2';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Duktape duktape;
String output = '';
@override
void initState() {
super.initState();
duktape = Duktape();
setState(() {
output = 'Initialized Duktape';
});
}
@override
void dispose() {
duktape.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 25);
const spacerSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Duktape Test'),
),
body: Center(
child: Container(
padding: const EdgeInsets.all(10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
output,
style: textStyle,
textAlign: TextAlign.center,
),
spacerSmall,
ElevatedButton(
child: const Text('Run JavaScript'),
onPressed: () {
duktape.evalString(jsCode);
setState(() {
output = '$jsCode => ${duktape.getInt(-1)}';
});
},
),
],
),
),
),
),
);
}
}