Android hybrid development (introducing the Flutter lib package into the original Android project project)

Summary A hybrid development is used in the project. I am using the first method settingsDir.parentFile。因为这样比较好管理代码。Android、IOS、Flutter 三个端各自处理自己代码。1.不会导致代码看的比较复杂。2.因为flutter项目需要在其他二端使用。所以选择了这个方案。

first step:

Create a new flutter module to introduce this module into the existing android native project.

Step two:

Add the following configuration to the settings.gradle file under the project root directory of the Android native project:

method one:

include ':app'                                    
setBinding(new Binding([gradle: this]))                                 
evaluate(new File( settingsDir.parentFile,'flutter名称/.android/include_flutter.groovy'                          
))  

Method Two:

include ':app'                                    
setBinding(new Binding([gradle: this]))                                 
evaluate(new File( settingsDir,'flutter名称/.android/include_flutter.groovy'                          
))  

The difference between these two methods:

The difference between these two writing methods lies in the location of the flutter module .
settingsDir.parentFileSpecify that the flutter  module project is at the same level as the Android app project directory.

If the directory is specified  settingsDir, it means that the module project is at the same level as the setting.gradle file, that is, the flutter  module project is inside the Android app project .

The advantages and disadvantages of these two methods:

第一种settingsDir.parentFile 

Advantages: 1. Flutter and app projects can write code independently of each other; 2. Two languages ​​can be written; 3. One person develops the flutter project and applies it to Android and ios.

Disadvantages: 1. To copy two folders, the flutter module project may be missed; 2. And it needs to be developed through two Android Studio windows.

第二种settingsDir

Advantages: 1. The project is easy to manage, which will not cause the problem of missing files; 2. One Android Studio window develops two projects.

Disadvantages: 1. The language is different, it is more troublesome to write code, and many codes have no prompts.

third step:

Add dependencies in the app's build.gradle, and then sync after adding, then flutter will be introduced into our project.

dependencies {
implementation project(':flutter')
}

the fourth step:

Sync the code. Finished at last.

Guess you like

Origin blog.csdn.net/hzqit520/article/details/122155360