This guide describes how to integrate Felgo into existing Android projects.
Felgo Native Integration comes as an Android aar library file. You can add it as a regular maven dependency.
-
Add the felgo-android dependency in your build.gradle file:
dependencies { implementation 'com.felgo:felgo-android:3.+' }
-
Add the Felgo Maven repository at the repositories block:
repositories { maven { url 'https://github.com/FelgoSDK/FelgoAndroid/raw/master/maven/' } }
-
Set the base class of any Activity that includes Felgo to
FelgoAndroidActivity
-
Add your QML code to the application assets. The following example uses the file
assets/qml/Main.qml
. -
Add
FelgoAndroidFragment
in layout or in source.-
From XML layout:
<fragment android:id="@+id/qt_fragment_container" class="com.felgo.ui.FelgoAndroidFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:qml_source="qml/Main.qml"/>
-
From source:
getFragmentManager().beginTransaction() .replace(R.id.qt_fragment_container, new FelgoAndroidFragment() .setQmlSource(getApplicationContext(), "qml/Main.qml"), null) .addToBackStack(null) .commit();
Note:
R.id.qt_fragment_container
must be a view in the current activity. -
The folder NativeIntegrationExample
contains a complete Android example project
making use of FelgoAndroid.
You can open it directly in Android Studio.