Skip to content

Modification to first try loading libflutter_engine.so from the asset bundle #206

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/flutter-pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ struct frame {
struct compositor;

enum flutter_runtime_mode {
kDebug, kRelease
kDebug, kProfile, kRelease
};

struct flutterpi {
Expand Down Expand Up @@ -426,6 +426,7 @@ struct flutterpi {
char *app_elf_path;
void *app_elf_handle;
char *icu_data_path;
char *libflutter_engine_path;

FlutterLocale **locales;
size_t n_locales;
Expand Down
31 changes: 26 additions & 5 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ OPTIONS:\n\
This also requires a libflutter_engine.so that was\n\
built with --runtime-mode=release.\n\
\n\
--profile Run the app in profile mode. The AOT snapshot\n\
of the app (\"app.so\") must be located inside the\n\
asset bundle directory.\n\
This also requires a libflutter_engine.so that was\n\
built with --runtime-mode=profile.\n\
\n\
-o, --orientation <orientation> Start the app in this orientation. Valid\n\
for <orientation> are: portrait_up, landscape_left,\n\
portrait_down, landscape_right.\n\
Expand Down Expand Up @@ -1341,7 +1347,7 @@ static int init_display(void) {

if (horizontal_dpi != vertical_dpi) {
// See https://github.com/flutter/flutter/issues/71865 for current status of this issue.
fprintf(stderr, "[flutter-pi] WARNING: display has non-square pixels. Non-square-pixels are not supported by flutter.\n");
fprintf(stderr, "[flutter-pi] WARNING: display has non-square pixels. Non-square-pixels are ;-).\n");
}
}

Expand Down Expand Up @@ -1680,7 +1686,18 @@ static int init_application(void) {
int ok;

libflutter_engine_handle = NULL;
if (flutterpi.flutter.runtime_mode == kRelease) {

libflutter_engine_handle = dlopen(flutterpi.flutter.libflutter_engine_path, RTLD_LOCAL | RTLD_NOW);

if (libflutter_engine_handle == NULL)
{
LOG_FLUTTERPI_ERROR(
"[flutter-pi] Warning: Could not load libflutter_engine.so inside the asset bundle : "
"%s. Trying to open libflutter_engine.so.${runtimeMode} ...\n",
dlerror());
}

if (flutterpi.flutter.runtime_mode == kRelease) {
libflutter_engine_handle = dlopen("libflutter_engine.so.release", RTLD_LOCAL | RTLD_NOW);
if (libflutter_engine_handle == NULL) {
LOG_FLUTTERPI_ERROR("[flutter-pi] Warning: Could not load libflutter_engine.so.release: %s. Trying to open libflutter_engine.so...\n", dlerror());
Expand Down Expand Up @@ -2094,7 +2111,7 @@ static int init_user_input(void) {


static bool setup_paths(void) {
char *kernel_blob_path, *icu_data_path, *app_elf_path;
char *kernel_blob_path, *icu_data_path, *app_elf_path, *libflutter_engine_path;
#define PATH_EXISTS(path) (access((path),R_OK)==0)

if (!PATH_EXISTS(flutterpi.flutter.asset_bundle_path)) {
Expand Down Expand Up @@ -2123,11 +2140,15 @@ static bool setup_paths(void) {
return false;
}

flutterpi.flutter.kernel_blob_path = kernel_blob_path;
asprintf(&libflutter_engine_path, "%s/libflutter_engine.so", flutterpi.flutter.asset_bundle_path);


flutterpi.flutter.kernel_blob_path = kernel_blob_path;
flutterpi.flutter.icu_data_path = icu_data_path;
flutterpi.flutter.app_elf_path = app_elf_path;
flutterpi.flutter.libflutter_engine_path = libflutter_engine_path;

return true;
return true;

#undef PATH_EXISTS
}
Expand Down