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.

Bild entfernt.

Further, for more convenience, open the native android part of the project in Android module.

Bild entfernt.

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.

Bild entfernt.

In android/app/src/main edit AndroidManifest.xml

Bild entfernt.

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.

Bild entfernt.

Now edit lib/main.dart: - add import 'package:flutter/services.dart'; - create _getMessage() method. - call our method from FloatingActionButton.

Bild entfernt.

So, in our flutter project, we successfully integrated and called a third-party android project.

Mehr davon

Get in touch

In Kontakt kommen

Frankfurt am Main, Germany (Sales)

60354

Eckenheimer Schulstraße, 20

+38 (098) 630-49-85

info@a5.ua

Kharkiv, Ukraina

61023

Trinklera Strasse, 9

+38 (050) 908-31-07

info@a5.ua

Burgas, Bulgaria (Development)

8008

бул. „Транспортна“ 15, Northern Industrial Zone

+359 877 350129

info@a5.ua