Imagine that you have already completed a flutter project, and here the client tells you that he has a ready Android project that he wants to add to the flutter project. Here you have two ways. Completely rewrite the Android application to the flutter or import it into the flutter project, which we will do. For example, I will use the application Chat-bot. So let's open Android Studio and create a new one Flutter project.
Further, for more convenience, open the native android part of the project in Android module.
In my case I will add the chat bot application from file .aar
In the modules tab we added a new module to our project .JAR/.AAR Package and on the Dependencies tab, we connected this module to our project. We have added a third-party Android project to our project.
In android/app/src/main edit AndroidManifest.xml
In android/build.gradle add JitPack allprojects{ repositories{ ….. maven{url 'https://jitpack.io'} } } JitPack checks out code, builds it and server the build artifacts (jar, aar). In android/app/build.gradle add the path to our module as well as the dependency it needs: dependendencies{ implamentation… … implamentation project (path: ':stda-bot') } Also need to configure support AndroidX - https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility We fully integrated Chat-bot into the flutter project. Now we need to create a channel through which we will call our Chat-bot from project flutter. In android/app/main/java/com.example/MainActivity create a channel and method in which we call our android application.
Now edit lib/main.dart: - add import 'package:flutter/services.dart'; - create _getMessage() method. - call our method from FloatingActionButton.
So, in our flutter project, we successfully integrated and called a third-party android project.