iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐙

Precautions for using firebase_dynamic_links when updating to Flutter 3.7

に公開

Introduction

When I updated to the Flutter 3.7 series, I encountered some issues regarding Dynamic Links, so I will share the solution here.

targetSdkVersion

When creating an Android app with Flutter, the default build.gradle configuration will look like the following:

android/app/build.gradle
android {
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    // ~~~ omitted
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
```text

These values, such as `flutter.targetSdkVersion`, are defined in the `flutter.gradle` file of the Flutter SDK.
The following is from the 3.7 series:

```gradle:packages/flutter_tools/gradle/flutter.gradle
/** For apps only. Provides the flutter extension used in app/build.gradle. */
class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 33

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 16

    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 33

    // ~~~ omitted
}
```text

This one is from the 3.3 series:

```gradle:packages/flutter_tools/gradle/flutter.gradle
/** For apps only. Provides the flutter extension used in app/build.gradle. */
class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 31

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 16

    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 31

    // ~~~ omitted
}
```text

Comparing them, you can see that `compileSdkVersion` and `targetSdkVersion` have increased from 31 to 33.

## Issues with Dynamic Links

In my case, as the targetSdkVersion changed to 33, an issue occurred where Dynamic Links could not be opened on Android 13 devices. I found that someone else encountered the same phenomenon in the following article, and I resolved it by applying the same fix.

<https://qiita.com/koichi-ozaki/items/883427922399788632a7>

### Solution

It is exactly as explained in the article above.

If you have a link like `https://hoge.page.link/?link=https://fuga.jp/&ius=xxx&apn=...`, the deep link part is `https://fuga.jp/&ius=xxx&apn=...`. It was necessary to add the host of this deep link to the intent-filter.

```diff xml:android/app/src/main/AndroidManifest.xml
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="hoge.page.link"
                    android:scheme="https" />
+               <data
+                   android:host="fuga.jp"
+                   android:scheme="https" />
            </intent-filter>

Summary

When upgrading the minor version of Flutter, caution is required because the targetSdkVersion also increases automatically. Especially when using firebase_dynamic_links, the issue can be resolved by adding the deep link host to the intent-filter. I hope this article will be helpful for anyone facing similar problems.

GitHubで編集を提案

Discussion