@@ -77,9 +77,11 @@ OPTIONS:\n\
77
77
pattern you use as a parameter so it isn't \n\
78
78
implicitly expanded by your shell.\n\
79
79
\n\
80
- --aot Run the app in AOT mode. The AOT snapshot\n\
80
+ --release Run the app in release mode. The AOT snapshot\n\
81
81
of the app (\"app.so\") must be located inside the\n\
82
82
asset bundle directory.\n\
83
+ This also requires a libflutter_engine.so that was\n\
84
+ built with --runtime-mode=release.\n\
83
85
\n\
84
86
-o, --orientation <orientation> Start the app in this orientation. Valid\n\
85
87
for <orientation> are: portrait_up, landscape_left,\n\
@@ -1568,7 +1570,9 @@ static int init_display(void) {
1568
1570
* FLUTTER INITIALIZATION *
1569
1571
**************************/
1570
1572
static int init_application (void ) {
1573
+ FlutterEngineAOTDataSource aot_source ;
1571
1574
FlutterRendererConfig renderer_config = {0 };
1575
+ FlutterEngineAOTData aot_data ;
1572
1576
FlutterEngineResult engine_result ;
1573
1577
FlutterProjectArgs project_args = {0 };
1574
1578
void * app_elf_handle ;
@@ -1632,54 +1636,44 @@ static int init_application(void) {
1632
1636
.compositor = & flutter_compositor
1633
1637
};
1634
1638
1635
- if (flutterpi .flutter .is_aot ) {
1636
- const uint8_t * vm_instr , * vm_data , * isolate_instr , * isolate_data ;
1637
-
1638
- app_elf_handle = dlopen (flutterpi .flutter .app_elf_path , RTLD_NOW | RTLD_LOCAL );
1639
- if (app_elf_handle == NULL ) {
1640
- perror ("[flutter-pi] Could not open \"app.so\". dlopen" );
1641
- return errno ;
1642
- }
1643
-
1644
- vm_instr = dlsym (app_elf_handle , "_kDartVmSnapshotInstructions" );
1645
- if (vm_instr == NULL ) {
1646
- perror ("[flutter-pi] Could not resolve vm instructions section in \"app.so\". dlsym" );
1647
- dlclose (app_elf_handle );
1648
- return errno ;
1649
- }
1650
-
1651
- vm_data = dlsym (app_elf_handle , "_kDartVmSnapshotData" );
1652
- if (vm_data == NULL ) {
1653
- perror ("[flutter-pi] Could not resolve vm data section in \"app.so\". dlsym" );
1654
- dlclose (app_elf_handle );
1655
- return errno ;
1656
- }
1657
-
1658
- isolate_instr = dlsym (app_elf_handle , "_kDartIsolateSnapshotInstructions" );
1659
- if (isolate_instr == NULL ) {
1660
- perror ("[flutter-pi] Could not resolve isolate instructions section in \"app.so\". dlsym" );
1661
- dlclose (app_elf_handle );
1662
- return errno ;
1663
- }
1639
+ bool engine_is_aot = FlutterEngineRunsAOTCompiledDartCode ();
1640
+ if (engine_is_aot && !flutterpi .flutter .is_aot ) {
1641
+ fprintf (
1642
+ stderr ,
1643
+ "[flutter-pi] The flutter engine was built for release (AOT) mode,\n"
1644
+ " but flutter-pi was not started up in release mode. \n"
1645
+ " Either you swap out the libflutter_engine.so \n"
1646
+ " with one that was built for debug mode, or you start\n"
1647
+ " flutter-pi with the --release flag and make sure\n"
1648
+ " a valid \"app.so\" is located inside the asset bundle\n"
1649
+ " directory.\n"
1650
+ );
1651
+ return EINVAL ;
1652
+ } else if (!engine_is_aot && flutterpi .flutter .is_aot ) {
1653
+ fprintf (
1654
+ stderr ,
1655
+ "[flutter-pi] The flutter engine was built for debug mode,\n"
1656
+ " but flutter-pi was started up in release mode.\n"
1657
+ " Either you swap out the libflutter_engine.so\n"
1658
+ " with one that was built for release mode, or you\n"
1659
+ " start flutter-pi without the --release flag.\n"
1660
+ );
1661
+ return EINVAL ;
1662
+ }
1664
1663
1665
- isolate_data = dlsym (app_elf_handle , "_kDartIsolateSnapshotData" );
1666
- if (isolate_data == NULL ) {
1667
- perror ("[flutter-pi] Could not resolve isolate data section in \"app.so\". dlsym" );
1668
- dlclose (app_elf_handle );
1669
- return errno ;
1664
+ if (flutterpi .flutter .is_aot ) {
1665
+ aot_source = (FlutterEngineAOTDataSource ) {
1666
+ .elf_path = flutterpi .flutter .app_elf_path ,
1667
+ .type = kFlutterEngineAOTDataSourceTypeElfPath
1668
+ };
1669
+
1670
+ engine_result = FlutterEngineCreateAOTData (& aot_source , & aot_data );
1671
+ if (engine_result != kSuccess ) {
1672
+ fprintf (stderr , "[flutter-pi] Could not load AOT data. FlutterEngineCreateAOTData: %s\n" , FLUTTER_RESULT_TO_STRING (engine_result ));
1673
+ return EIO ;
1670
1674
}
1671
1675
1672
- project_args .vm_snapshot_instructions = vm_instr ;
1673
- project_args .vm_snapshot_instructions_size = 0 ;
1674
-
1675
- project_args .isolate_snapshot_instructions = isolate_instr ;
1676
- project_args .isolate_snapshot_instructions_size = 0 ;
1677
-
1678
- project_args .vm_snapshot_data = vm_data ;
1679
- project_args .vm_snapshot_data_size = 0 ;
1680
-
1681
- project_args .isolate_snapshot_data = isolate_data ;
1682
- project_args .isolate_snapshot_data_size = 0 ;
1676
+ project_args .aot_data = aot_data ;
1683
1677
}
1684
1678
1685
1679
// spin up the engine
@@ -2328,11 +2322,11 @@ static bool parse_cmd_args(int argc, char **argv) {
2328
2322
bool input_specified = false;
2329
2323
int opt ;
2330
2324
int longopt_index = 0 ;
2331
- int is_aot_int = false;
2325
+ int is_release_int = false;
2332
2326
int disable_text_input_int = false;
2333
2327
2334
2328
struct option long_options [] = {
2335
- {"aot " , no_argument , & is_aot_int , true},
2329
+ {"release " , no_argument , & is_release_int , true},
2336
2330
{"input" , required_argument , NULL , 'i' },
2337
2331
{"orientation" , required_argument , NULL , 'o' },
2338
2332
{"rotation" , required_argument , NULL , 'r' },
@@ -2428,7 +2422,7 @@ static bool parse_cmd_args(int argc, char **argv) {
2428
2422
2429
2423
flutterpi .input .use_paths = input_specified ;
2430
2424
flutterpi .flutter .asset_bundle_path = strdup (argv [optind ]);
2431
- flutterpi .flutter .is_aot = is_aot_int ;
2425
+ flutterpi .flutter .is_aot = is_release_int ;
2432
2426
flutterpi .input .disable_text_input = disable_text_input_int ;
2433
2427
flutterpi .input .input_devices_glob = input_devices_glob ;
2434
2428
0 commit comments