Solution 1 :
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.
Solution 2 :
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.
Problem :
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
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?
Comments
Comment posted by aSemy
Have you tried
Comment posted by Adrien
works perfectly for me too, thanks
Comment posted by Adrien
I’ll take a look at that, does compose run natively on ios and android?
Comment posted by mipa
On Android yes, on iOS the comparable variant is still experimental. It also runs on desktop (JVM) and native on macOS, Linux and Windows and it also runs in the Web.