Android Flutter hybrid development process and a series of problems (suitable for new learners)

Android flutter hybrid development process

First of all, I want to say that I also started to learn the hybrid development of Android and Flutter following the big steps. It was really difficult. It took more than a day to configure it (I am still too stupid and ashamed). Okay, let’s start the topic. .

First, configure Android and lfutter module according to the process. The premise is that your studio has already configured the plug-in, as shown below (the latest version is fine, don’t worry about restoring the old version):

One is a Flutter plug-in and the other is Dart.
Okay, let’s keep going. Then it’s easy to create a new Android project. For example, my new project is MyFlutterT . The next step is to create a new flutter module . The key begins (Note: My AndroidStudio is the latest version of Little Bee version 2021.1.1). As shown below:

first picture

In the second picture, pay attention to the sdk path of flutter.
The third picture is also very important to note two points. First, if the project type is Module, the path of the second module is the same level as your own Android project.
Location same level

Then it’s finish

Okay, this is the new creation completed. Of course, the later configuration is as follows:

The first step is to check whether the flutter module has a build file and an internal aar file at the location shown below;
Insert image description here
if not, then you need to configure it. The method is simple. Enter two instructions in the following location of your Android project. The premise is that flutter is located. In the module location, let me first talk about the command. The first one is cd .android and the second one is gradlew assembleDebug (after a while, there will be a green letter after the execution is completed, which means it is completed). Then look at the flutter module
That's ok
file and there will be one more. The build file naturally also has an aar file in it.

Then, continue the big steps, configure the Android project, as shown in the picture below, the above picture
Remember to clean up all other codes above rootProject.name.
is also the key point to pay attention to, configure the red circle code in setting.gradle, modify the name of your flutter module, and then, my blood and tears experience Here it comes, that is, once you find that Binding is reporting red, you must never import the package. I didn’t understand it at first, and I fell into the trap many times. After the later configuration is successful, the build will be normal. Well, the second picture
is Gradle in the app, the configuration is as shown below.
No need to question, just write flutter
If JavaVersion 1.8 is not specified, remember to add it;
then, I thought it was over and it could be built, but it was not. When I ran it, I reported the following
This interface is another project, it is similar, right?
error. If such an error occurs , Don’t panic, hahaha, then you need to configure the gradle and sdk versions. Modify them to be similar to the flutter module, which may not necessarily be the same. As shown below, the first part is the three pictures of the Android part of the flutter module:
Insert image description here
Insert image description here
Insert image description here

Pay attention to the red circle in the above three pictures, and then there is the corresponding configuration of the Android project, as shown below:
Insert image description here
Insert image description here
Insert image description here
Note that it may be different from the flutter module, because, at the beginning, it is written the same, and then an error is reported, prompting Modify the corresponding ones. For specific situations, you will first change it to a configuration similar to the flutter module, and then modify it.
ok. Then the final step is to use build or try again, etc. The Android project directory will look like the following:

Insert image description here

The project will no longer report errors, and then it’s time to run the Android project. Hahahahaha. That’s the end. I’m not good at blogging. There are too many languages, so please forgive me for not being concise.

Note that this address is the key to my sudden solution to the problem: https://blog.csdn.net/shulianghan/article/details/119956323

Guess you like

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