简体   繁体   中英

Using flutter module in kotlin multiplatform app

I created an application with kotlin multiplatform and I want now to use flutter to develop the UI once. I followed the tutorial to integrate flutter in an already existing Android app and I choose option B to compile everything in one step.

The first trouble is including the Flutter module as a subproject in the host app: in the kotlin multiplatform project, I have to rename the settings.gradle.kts to settings.gradle . Then I have another error I can't get rid of: Caused by: java.lang.AssertionError: Project :app doesn't exist. To custom the host app project name, set 'org.gradle.project.flutter.hostAppProjectName=<project-name>' in gradle.properties.. Expression: (appProject != null). Values: appProject = null Caused by: java.lang.AssertionError: Project :app doesn't exist. To custom the host app project name, set 'org.gradle.project.flutter.hostAppProjectName=<project-name>' in gradle.properties.. Expression: (appProject != null). Values: appProject = null

I understand what the error means: with kotlin multiplatform, the project is not called app but the name of the app, in my case MusicTraining . So as mentioned in the kotlin documentation:

Tip: By default, the host app provides the: app Gradle project. To change the name of this project, set flutter.hostAppProjectName in the Flutter module's gradle.properties file. Finally, include this project in the host app's settings.gradle file mentioned below.

So, in the flutter module's gradle.properties file I tried to add the lines:

  • flutter.hostAppProjectName="MusicTraining"
  • flutter.hostAppProjectName=":MusicTraining"

I still have the same error.

I tried with vscode to change all instances of :app to :MusicTraining but nothing works. I still have the same error.

As the error mention, I tried to add the line

  • org.gradle.project.flutter.hostAppProjectName="MusicTraining"
  • org.gradle.project.flutter.hostAppProjectName=":MusicTraining"

in the flutter module's gradle.properties file, but still the same error.

How can I integrate a flutter module in a kotlin multiplatform app?

Try to add flutter.hostAppProjectName=MusicTraining into gradle.properties file with both Flutter module and you root project.

Notice: run you native application, If you run main.dart, you still get this error

I face the same problem, this works for me.

If you already have a Kotlin multiplatform project, I'd use Jetbrains Compose multiplatform instead of Flutter. Compose is very similar to Flutter and you would avoid the technology split.

https://www.jetbrains.com/de-de/lp/compose-mpp/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM