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

Support multi package app #143

Closed
jkpu opened this issue Jun 21, 2021 · 21 comments
Closed

Support multi package app #143

jkpu opened this issue Jun 21, 2021 · 21 comments
Assignees
Labels
enhancement New feature or request

Comments

@jkpu
Copy link

jkpu commented Jun 21, 2021

I need flutter multi package app (UI app + service app).
Tizen native app and .NET app supports multi package.
Each project can refer to other project's code and can access files and database in the package installed directory.
It will be very helpful if Tizen flutter app supports multi package.

Native app
https://docs.tizen.org/application/native/tutorials/process/app-dev-process/#developing-multiple-projects-as-a-combined-package

.NET app
https://developer.samsung.com/tizen/blog/en-us/2019/01/04/how-to-package-ui-and-service-applications-together-and-perform-them

@jkpu jkpu changed the title Support multi package App Support multi package app Jun 21, 2021
@swift-kim swift-kim added the enhancement New feature or request label Jun 21, 2021
@pkosko
Copy link
Contributor

pkosko commented Jun 29, 2021

I will check the feasibility of this feature if it is not assigned yet.

@pkosko pkosko self-assigned this Jun 29, 2021
@swift-kim
Copy link
Member

@jkpu How does the TPK with UI app + service app look like? Is the source code of the two apps compiled into a single executable under bin or do they have separate entrypoints?

@jkpu
Copy link
Author

jkpu commented Jun 29, 2021

@swift-kim No. UI app and service app has each own executable, they only package in same folder.
You can refer to native app example or .Net example in the above link.

following is the result I have tested with native UI app + service app

/opt/usr/home/owner/apps_rw/org.example.basicui
sh-3.2# ls -al
total 32
drwxr-xr-x   5 owner  users        4096 Jun 29 16:35 .
drwxr-x--- 106 owner  system_share 4096 Jun 29 16:35 ..
lrwxrwxrwx   1 app_fw app_fw         60 Jun 29 16:35 author-signature.xml -> /opt/usr/globalapps/org.example.basicui/author-signature.xml
lrwxrwxrwx   1 app_fw app_fw         43 Jun 29 16:35 bin -> /opt/usr/globalapps/org.example.basicui/bin
drwxr-sr-x   2 owner  system_share 4096 Jun 29 16:35 cache
drwxr-sr-x   2 owner  system_share 4096 Jun 29 16:35 data
lrwxrwxrwx   1 app_fw app_fw         43 Jun 29 16:35 lib -> /opt/usr/globalapps/org.example.basicui/lib
lrwxrwxrwx   1 app_fw app_fw         43 Jun 29 16:35 res -> /opt/usr/globalapps/org.example.basicui/res
drwxr-xr-x   3 owner  users        4096 Jun 29 16:35 shared
lrwxrwxrwx   1 app_fw app_fw         58 Jun 29 16:35 tizen-manifest.xml -> /opt/usr/globalapps/org.example.basicui/tizen-manifest.xml
sh-3.2# cat tizen-manifest.xml 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="4.0" package="org.example.basicui" version="1.0.0">
    <profile name="mobile"/>
    <ui-application appid="org.example.basicui" exec="basicui" launch_mode="single" multiple="false" nodisplay="false" taskmanage="true" type="capp">
        <label>basicui</label>
        <icon>basicui.png</icon>
    </ui-application>
    <service-application appid="org.example.testservice" exec="testservice" multiple="false" nodisplay="true" taskmanage="false" type="capp">
        <label>testservice</label>
        <icon>testservice.png</icon>
    </service-application>
</manifest>
sh-3.2# cd bin/
sh-3.2# ls -al
total 52
drwxr-xr-x 2 tizenglobalapp root  4096 Jun 29 16:35 .
drwxr-xr-x 6 tizenglobalapp root  4096 Jun 29 16:35 ..
-rwxr-xr-x 1 tizenglobalapp root 24192 Jun 29 16:35 basicui
-rwxr-xr-x 1 tizenglobalapp root 15032 Jun 29 16:35 testservice

@swift-kim
Copy link
Member

There are many places in the tool that assume a single platform project for a single Flutter project and it would not be easy to re-design them all in a clean manner. If we really need to implement this feature, we will have to be very careful not to break any other even small features.

@swift-kim
Copy link
Member

@pkosko I'll look into this issue if no progress has been made yet.

@pkosko
Copy link
Contributor

pkosko commented Jul 21, 2021

hello, I've made significant progress.
Currently I have a working draft code for simple applications (ui + service) - pkosko@2c9c385
What I've already done:

  • separate runners, flutter_assets and plugins for every application by adding appId suffix
  • change the build method to support multiple packages in one tpk.
  • add feature of scanning 'tizen_services' directory for existing sub applications
  • running two apps together with 'flutter-tizen run'

For now, many cases still need to be checked, but I am doing progress every day. My TODO list:

  • support automatic rebuild of services when the 'mother' application build is happening (in progress)
  • check if everything works fine in applications using some plugins inside
  • check also release mode of application build
  • check and support hot reload of service application
  • clean the code from any temporary logs
  • checking and optimization of 'common' application files to decrease redundancy
  • (optional) add some flutter-tizen command supporting creation of service inside application

If you have any comments, please share.

@swift-kim
Copy link
Member

swift-kim commented Jul 21, 2021

@pkosko What I had in mind was to make the multi package app into a single Dart package, by creating multiple entry points in the Dart code (one for the UI app and one for the service app). In that way only small changes (tentatively) need to be made, like adding a template for a multi app project and adding a new (or modifying existing) build target to build a multi app project. That's why I mentioned this issue might depend on flutter-tizen/engine#149.

@pkosko
Copy link
Contributor

pkosko commented Jul 21, 2021

Sorry, I didn't notice the 'mention' and I focused on creating support for service on 'tizen' level, not 'dart'.

Now I need to make a deeper look at the concept explained in flutter-tizen/engine#111 and flutter-tizen/engine#149, and make some checking on my side to understand it.

For now I am not sure if I understand all your expectations regarding this issue. Could you please share the list of TODO things, that I can follow to avoid misunderstandings?

@swift-kim
Copy link
Member

Sorry. I had to make the comment in this issue but not in the engine issue. (It's always good to share progress frequently if the work takes longer than you thought. :D)

I don't yet have a complete roadmap of what need to be done, and I just want to make things clear first. Do you know if I can create a single TPK which contains both UI and service apps within it by only using the Tizen CLI?

@pkosko
Copy link
Contributor

pkosko commented Jul 21, 2021

I've used a https://developer.tizen.org/development/tizen-studio/web-tools/cli#Build_pack_multi_proj command as it is here: pkosko@2c9c385#diff-32efabcee487e07581c54bc0c3ac9e16b5401ebd7b15ad5337b96186fe36b41cR821 , but in my case the build targets were two Flutter-Tizen projects (one with UI and second a service only). CLI makes all necessary operations to pack them together into one TPK (including merging tizen-manifest.xml files and other resources).

@swift-kim
Copy link
Member

swift-kim commented Jul 21, 2021

Thanks. I have two basic template projects created by Tizen Studio:

$ ls -l
total 48
drwxr-xr-x 1 swift swift  4096 Jul 21 17:22 MultiApp
drwxr-xr-x 1 swift swift  4096 Jul 21 17:22 MultiAppService

and I used this command to package the projects into a TPK:

tizen build-app -m 'name: "m1", compiler: "llvm", configs:["Release"], arch:"arm"' -b 'name: "b1", methods: ["m1"], targets: ["MultiApp","MultiAppService"]' -p 'name: "test", targets: ["b1"]' -- .

The file test_Wearable-6.0_i386.tpk was generated as a result. I think something has gone wrong but I'll take a detailed look tomorrow.

edit)

This command worked:

tizen build-app -m 'name: "m1", compiler: "llvm", configs:["Release"], rootstraps: [{name:"wearable-6.0-device.core",platform:"wearable-6.0",arch:"arm"}]' -b 'name: "b1", methods: ["m1"], targets: ["MultiApp","MultiAppService"]' -p 'name: "test", targets: ["b1"]' -- .

@pkosko
Copy link
Contributor

pkosko commented Jul 21, 2021

For the test project I used (notice that arch is inside a rootstraps property of method):

tizen build-app -m 'name:"m1", compiler: "llvm-10.0", configs: ["Debug"], rootstraps: [{name:"wearable-4.0-arm.flutter", platform:"wearable-4.0", arch:"arm"}]' -b 'name: "b1", methods: ["m1"], targets: ["test_project"]' -p 'name: "test", targets:["b1"]'
this makes an arm tpk.

An important conclusions from my work was that to pass additional linker flags, it is needed to use a 'hidden' option of rootstrap - 'extraoption:' (as it is here). This is not documented behaviour, but I found it in CLI code.

@swift-kim
Copy link
Member

swift-kim commented Jul 22, 2021

So my design is simple:

  • There's one Flutter project, and the project contains two Tizen projects inside its tizen directory.
  • The Tizen projects share the same Dart code. That is, only a single set of flutter_assets and libapp.so is generated.
  • The Dart code contains two entry points: main() for the UI app, and service_main() for the service app.
  • main() and service_main() are called by the UI app and service app respectively when they start.

The idea of sharing of Dart code between apps makes sense for me, although you guys might have different opinions.

In order to implement the design, we need several things to be done:

Tip) You can debug the flutter-tizen tool without using many prints: https://github.com/flutter-tizen/flutter-tizen/wiki/Debugging-the-flutter%E2%80%91tizen-tool

@bwikbs
Copy link
Member

bwikbs commented Jul 22, 2021

After implementation of this is completed, I guess it will be possible to use it for multi-screen scenario. 😄 (flutter-tizen/engine#94)
I think I could just focus on FlutterEngineGroup for optimization.

@pkosko
Copy link
Contributor

pkosko commented Jul 23, 2021

@swift-kim Thanks for the tip about running flutter-tizen with debugger attached, it will be much more convenient.
Would you like me to take care of some steps from your TODO list? If so, which ones?

@swift-kim
Copy link
Member

@pkosko Anything you want, if you want to contribute to the project. :)

Please beware that #171 and #167 are not merged to master yet.

@pkosko
Copy link
Contributor

pkosko commented Jul 26, 2021

@swift-kim I've got a question to:

Create a new template (multi-app) next to ui-app and service-app. The template should consist of two separate directories for UI app project and service app project. The service app's runner should be configured to pass service_main to the embedder as an entry point.

Do we assume that only single service can be added to application or we should support multiple services?

@swift-kim
Copy link
Member

@pkosko AFAIK up to 3 or 4 service apps can be packaged into a single package but I don't think there's such a requirement or use case. I think we can basically assume at most one service app within a package.

cc @jkpu

@pkosko
Copy link
Contributor

pkosko commented Jul 28, 2021

Ok, I will base on the assumption that only one service application is supported.

@pkosko
Copy link
Contributor

pkosko commented Aug 17, 2021

I've managed to achieve the goal of this enhancement - application including a ui and service parts packed into single TPK file.
https://github.com/pkosko/flutter-tizen/tree/multipackage_add_template.

My code:

  • supports cpp style multi-applications
  • use a tizen/internal/app_control_method channel for starting a service (stoping currently doesn't work - needs further investigation)
  • was tested for ui-only application and multi-applications:
    • creation and build
    • running application on the device
    • running application in debug mode
    • running an application which uses some dart plugin
      all above seem to work as expected.

Starting a service from multi-application seem to work well, other process is launched.

Now I need to rebase the code to base on changes introduced with #181, after that I will make a PR.

@pkosko
Copy link
Contributor

pkosko commented Aug 30, 2021

https://github.com/flutter-tizen/flutter-tizen/wiki/Application-types - multi app feature described on this page.
I think that we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants