jwinarske / meta-flutter

Yocto meta layer for recipes related to using Google Flutter Engine
MIT License
45 stars 22 forks source link

running flutter-gallery on rpi 3 #33

Closed gmpbigsun closed 3 years ago

gmpbigsun commented 3 years ago

Hey I was wondering if you could tell me how to run the gallery app on the raspberry pi

I followed the readme and setup everything to make the DRM version work. The flutter-pi command itself is working however I'm not sure how to run the gallery-app

running "flutter-pi /usr/share/flutter-gallery/sony/data/flutter_assets leaves me with an error telling me that there's no icutl.dat file inside /usr/share/flutter/

and running "flutter-pi /usr/share/flutter-gallery/sony/data/" tells me that there's no kernel.blob file inside "/usr/share/flutter-gallery/sony/data/" for debug mode

trying to run in release mode is telling me that there's no app.so inside the data folder

Charlie9830 commented 3 years ago

Hi gmpbigsun. I may be able to help.

By default, the flutter-gallery recipe installs the app bundle using the "Sony" layout. Which itself renames app.so to libapp.so and splits the bundle into a data/ and lib/ directory. This makes it compatible with the Sony embedders but unfortunately confuses flutter-pi.

To make this work for flutter-pi you can manually move libapp.so from the /lib directory over to the /data directory then rename it to app.so. Then point flutter-pi to the data/ directory as it's target bundle directory.

A more permanent solution is to modify the flutter-gallery recipe (and any subsequent recipes you use for your own flutter apps). Specifically the compile and install steps, I've included the steps from my recipe below but I'll list the specific changes I made first.

With that done. At runtime I can run my app castboard-player with the following command.

flutter-pi --release /usr/share/castboard-player/flutter_assets

Recipe Changes

do_compile() {
    export PATH=${STAGING_DIR_NATIVE}/usr/share/flutter/sdk/bin:$PATH

    ENGINE_SDK=${S}/engine_sdk/sdk

    cd ${S}

    flutter build bundle
    dart ${ENGINE_SDK}/frontend_server.dart.snapshot --aot --tfa --target=flutter --sdk-root ${ENGINE_SDK} --output-dill app.dill lib/main.dart
    ${ENGINE_SDK}/clang_x64/gen_snapshot --deterministic --snapshot_kind=app-aot-elf --elf=app.so --strip app.dill
}

do_install() {

    #
    # Sony Layout
    #
    #install -d ${D}${datadir}/${PN}/sony
    #
    #install -d ${D}${datadir}/${PN}/sony/lib
    #install -m 644 ${S}/libapp.so ${D}${datadir}/${PN}/sony/lib
    #
    #install -d ${D}${datadir}/${PN}/sony/data
    #install -m 644 ${STAGING_DATADIR}/flutter/icudtl.dat ${D}${datadir}/${PN}/sony/data/
    #
    #install -d ${D}${datadir}/${PN}/sony/data/flutter_assets
    #cp -rTv ${S}/build/flutter_assets/. ${D}${datadir}/${PN}/sony/data/flutter_assets/

    #
    # Flutter-Pi Layout
    #
    install -d ${D}${datadir}/${PN}/

    install -d ${D}${datadir}/${PN}/flutter_assets/
    install -m 644 ${S}/app.so ${D}${datadir}/${PN}/flutter_assets/

    install -m 644 ${STAGING_DATADIR}/flutter/icudtl.dat ${D}${datadir}/${PN}/

    cp -r ${S}/build/flutter_assets/* ${D}${datadir}/${PN}/flutter_assets/
}
gmpbigsun commented 3 years ago

Hi gmpbigsun. I may be able to help.

By default, the flutter-gallery recipe installs the app bundle using the "Sony" layout. Which itself renames app.so to libapp.so and splits the bundle into a data/ and lib/ directory. This makes it compatible with the Sony embedders but unfortunately confuses flutter-pi.

To make this work for flutter-pi you can manually move libapp.so from the /lib directory over to the /data directory then rename it to app.so. Then point flutter-pi to the data/ directory as it's target bundle directory.

A more permanent solution is to modify the flutter-gallery recipe (and any subsequent recipes you use for your own flutter apps). Specifically the compile and install steps, I've included the steps from my recipe below but I'll list the specific changes I made first.

* In do_compile() changed the `--elf=libapp.so` to `--elf=app.so`

* In do_install() disabled the Sony layout steps (I still plan to use the Sony embedders in the future)

* In do_install() I drop the `sony` subdirectory and instead just install `app.so` into a the `flutter_assets` directory.

With that done. At runtime I can run my app castboard-player with the following command.

flutter-pi --release /usr/share/castboard-player/flutter_assets

Recipe Changes

do_compile() {
    export PATH=${STAGING_DIR_NATIVE}/usr/share/flutter/sdk/bin:$PATH

    ENGINE_SDK=${S}/engine_sdk/sdk

    cd ${S}

    flutter build bundle
    dart ${ENGINE_SDK}/frontend_server.dart.snapshot --aot --tfa --target=flutter --sdk-root ${ENGINE_SDK} --output-dill app.dill lib/main.dart
    ${ENGINE_SDK}/clang_x64/gen_snapshot --deterministic --snapshot_kind=app-aot-elf --elf=app.so --strip app.dill
}

do_install() {

    #
    # Sony Layout
    #
    #install -d ${D}${datadir}/${PN}/sony
    #
    #install -d ${D}${datadir}/${PN}/sony/lib
    #install -m 644 ${S}/libapp.so ${D}${datadir}/${PN}/sony/lib
    #
    #install -d ${D}${datadir}/${PN}/sony/data
    #install -m 644 ${STAGING_DATADIR}/flutter/icudtl.dat ${D}${datadir}/${PN}/sony/data/
    #
    #install -d ${D}${datadir}/${PN}/sony/data/flutter_assets
    #cp -rTv ${S}/build/flutter_assets/. ${D}${datadir}/${PN}/sony/data/flutter_assets/

    #
    # Flutter-Pi Layout
    #
    install -d ${D}${datadir}/${PN}/

    install -d ${D}${datadir}/${PN}/flutter_assets/
    install -m 644 ${S}/app.so ${D}${datadir}/${PN}/flutter_assets/

    install -m 644 ${STAGING_DATADIR}/flutter/icudtl.dat ${D}${datadir}/${PN}/

    cp -r ${S}/build/flutter_assets/* ${D}${datadir}/${PN}/flutter_assets/
}

Hey @Charlie9830 Thanks for the very helpful answer That definitely explains why I wasn't able to do it. Now it's working as intended.