Install Flutter SDK
Prerequisites
Before you begin setting up the Flutter SDK for Android and iOS, ensure the following prerequisites are met. The files mentioned for the prerequisites are available in the flutter-hydra-lib.git repository.
1. Configure continuous integration and continuous delivery (CI/CD)
To set up CI/CD, follow these steps:
- Set the environment variables listed in
hydra_github_cred.env
. Ensure the variable names and values match exactly what is in the file. - After setting the environment variables, run the
setup_cicd.sh
script.
2. Configure the developer system
Use the setup_local.sh
script to set up your system. To setup the environment follow these steps:
- Place the
hydra_github_cred.env
andsetup_local.sh
files in the same folder. - Open Terminal and change the current working directory to that folder.
- Run the following command:
./setup_local.sh
- After the script finishes, restart your terminal. If you are using VS Code or Android Studio, restart the editor.
Installing Flutter SDK
You need to add two dependencies to your pubspec.yaml
file. The ref
parameter specifies a particular version of the dependency. When specifying the version number , ensure you prefix it with "v".
Add the following dependencies to your pubspec.yaml
:
capillary_hydra:
git:
url: https://github.com/Capillary/flutter-hydra-lib.git
ref: v1.0.2
path: capillary_hydra
capillary_hydra_platform_interface:
git:
url: https://github.com/Capillary/flutter-hydra-lib.git
ref: v1.0.2
path: capillary_hydra_platform_interface
To add a configuration file as an asset in your project, follow these steps:
- Create a folder named
capillary
in the root directory of your Flutter project. - Rename the
hydra-config.json
template file tohydra-config.json
and move the file to thecapillary
folder. - Optionally, change the values in the
hydra-config.json
file as required for your project. - In your pubspec.yaml, add the capillary folder to the assets section as shown below:
assets: - capillary/
- Get the dependencies by running this command in your terminal:
flutter pub get
- Invoke initializer for Hydra plugin in main function before
runApp
using the following:WidgetsFlutterBinding.ensureInitialized(); HydraInitializer.initialize();
Platform Specific Setup
Once you have installed the Flutter SDK, you can install the platform specific SDKs (Android and iOS).
Installing Android SDK
To configure Android for Flutter, follow these steps:
- Add GitHub Maven credentials to your project's build file.
- If your app uses
android/build.gradle.kts
(Kotlin), add the following block to theallprojects
>repositories
section:allprojects { repositories { // ... other repositories maven { url = uri("https://maven.pkg.github.com/Capillary/hydra-sdk-android-maven") credentials { username = System.getenv("HYDRA_GITHUB_USER_NAME") password = System.getenv("HYDRA_GITHUB_PAT") } } } }
- If your app uses
android/build.gradle
(Groovy), add the following block to theallprojects
>repositories
section:allprojects { repositories { // ... other repositories maven { url "https://maven.pkg.github.com/Capillary/hydra-sdk-android-maven" credentials { username System.getenv("HYDRA_GITHUB_USER_NAME") password System.getenv("HYDRA_GITHUB_PAT") } } } }
- If your app uses
- Update the Application class name in your
android/app/src/main/AndroidManifest.xml
. By default, Flutter apps do not use a custom Application class in Android, but the SDK requires one for initialization. Find the tag and set its android:name attribute to "com.capillary.plugins.hydra.HydraApplication" as shown in this example:<application android:name="com.capillary.plugins.hydra.HydraApplication" ...> </application>
Note
If you are using your own Application class or plan to use another CMS, follow the steps in the Advanced Android setup documentation instead of this step.
- Set an
AppCompat
theme for your application in yourAndroidManifest.xml
. The SDK requires that your application theme is set to an AppCompat theme. If your app's theme is not already set to anAppCompat
theme, add or update theandroid:theme
attribute within the tag as shown in this example:<application ...> android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" > </application>
Installing iOS SDK
If Swift Package Manager is already enabled in your project, you can skip the first two steps below and proceed to the remaining steps. Otherwise, follow all steps
To setup for iOS, follow these steps:
-
Add the following to the top of the iOS/Podfile:
require_relative './.symlinks/plugins/capillary_hydra_ios/script/HydraPods.rb'
-
Add the following in the
target 'Runner'
section of the iOS/Podfile:target 'Runner' do use_frameworks! hydra_pods # Add this line flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) target 'RunnerTests' do inherit! :search_paths end end
-
Open your terminal, change the current working directory to the ios folder of your project, and run the following command:
pod install
If you are using another CMS, follow the steps in the Advanced iOS Setup documentation instead.
Updated about 4 hours ago