Mixed development of Android and Flutter

Add flutter module to Android project

The first step is to use studio to create a new Android project. Everyone knows how to do it.

In the second step, use the command box at the bottom of the studio to create the flutter module, as shown below.
Insert image description here
Note that to check the file path, it must be in the Android project directory, and then enter the command flutter create -t module flutter_module. Remember not to omit the module, otherwise it will be a new flutter project.

In the third step, after creating a new flutter module, you also need to create a new aar file.
Similarly, switch the path in the command box cd flutter_module, and then enter the command as shown below:
Insert image description here
Then the aar will be found in the location of the flutter module, as shown below:
Insert image description here
The fourth step is to configure On the one hand,
it is configured in the setting.gradle of the Android project and in the build.gradle of the app, as shown below:
Insert image description here

Pay attention to the above picture. Delete the location code in Figure 1. Do not import the Binding in the location in Figure 2. Remember, don’t worry about it. ReBuild later and it will not become popular. Remarks, the following code is what I improved later
. Yeah, I’m too lazy to change the picture above, it’s just a reminder;

 setBinding(new Binding([gradle: this]))
evaluate(new File(
        settingsDir.parentFile,
        'flutter_module/.android/include_flutter.groovy'
))
include ':flutter_module'
project(':flutter_module').projectDir = new File('../flutter_module')

Then the picture below is the configuration of gradle in the app:
Insert image description here
just add the dependency of flutter, and then synchronize in the upper right corner. Remember to enter flutter, which is different from the usual import dependency. It does not have to have the same name as the module.

The fifth step is to debug the problem.
When I get here, 自然的会出问题了,那是因为 flutter module中的安卓模块的gradle和本项目的安卓gradle配置不一致造成的,修改为统一就行,大概提示一下吧, 比如sdk最高是31 ,最低是16 ,然后gradle我的对应是 4.2.1 和 6.7.1,具体大家根据个人情况,备注,不是必须版本号都一样哦,先修改一直后,try again 后,根据错误提示来修改,I will post the error after synchronization:
Insert image description here
This error is my first time as a novice. It tortured me for a long time, and I am still too technical. Hahaha
, for this error, Just as I mentioned the red text above, just modify it. As for the new flutterActivity later, you can search it online, so I will post the key hybrid development configuration. Sorry for the bad writing.

Guess you like

Origin blog.csdn.net/mawlAndroid/article/details/124861260