RodrigoSMarques / flutter_branch_sdk

Flutter Plugin for create deep link using Branch Metrics SDK. This plugin provides a cross-platform (iOS, Android, Web).
https://branch.io
MIT License
100 stars 90 forks source link

How to setup multiple flavors of app in Flutter? #324

Closed MarufHassanPietech closed 4 months ago

MarufHassanPietech commented 6 months ago

Describe the bug We have a app which has three flavors - dev, stg, prod. We have created 3 apps in Branch.io dashboard for 3 flavors. My problem is with the info.plist file. How do I differentiate the different flavors for it?

Code

        <key>branch_key</key>
        <dict>
            <key>live</key>
            <string>key_live_cDfD4sdaasdcaim7Z</string>
            <key>test</key>
            <string>key_test_oEiBY3bdsdsdsnxmj</string>
        </dict>
        <key>branch_universal_link_domains</key>
        <array>
            <string>dsa.test-app.link</string>
            <string>bsd2-alternate.test-app.link</string>
            <string>dsas.app.link</string>
            <string>dadw-alternate.app.link</string>
        </array>

This code is for dev flavor according to Branch.io data[Not original keys & link]. How does my app differentiate if it should use this or any other data for a particular flavor. What should I write for other flavors?

RodrigoSMarques commented 6 months ago

@MarufHassanPietech

This package calls Branch Native SDK functions on each platform.

The doubt reported is not in the Flutter plugin, but in the Native SDK.

Please open an issue in the platform repository:

iOS: https://github.com/BranchMetrics/ios-branch-deep-linking-attribution Android: https://github.com/BranchMetrics/android-branch-deep-linking-attribution Or open a support ticket for Branch at the link

RodrigoSMarques commented 6 months ago

@MarufHassanPietech

In addition.

You don't need to create 3 applications.

Each application has 2 environments: Test and Production with different url and keys.

In the Branch configuration dashboard, there is a switch where you can see the settings for each environment.

You can configure the use of the test key, according to the REAME.MD instructions.

To save work for your environments, configure dev and stg to use the same key, which would be the test key.

MarufHassanPietech commented 5 months ago

@RodrigoSMarques I tried using only one app in Branch.io as you suggested. I have three flavors dev - Flavor.superbrains_dev, stg - Flavor.superbrains_stg, prod - Flavor.superbrains

This is my configuration in Android Manifest. [Not original keys & link]

      <!-- START: SUPERBRAINS BRANCH -->
      <!-- Branch App Links - SUPERBRAINS Live App -->
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
                    android:host="d3ksadwf1.app.link"
                    android:scheme="https" />
        <data
                    android:host="ddsa3kwf1-alternate.app.link"
                    android:scheme="https" />
      </intent-filter>
      <!-- Branch App Links - SUPERBRAINS Test App -->
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
                    android:host="d3axaakf1.test-app.link"
                    android:scheme="https" />
        <data
                    android:host="d3sadwkf1-alternate.test-app.link"
                    android:scheme="https" />
      </intent-filter>
      <meta-data
            android:name="io.branch.sdk.BranchKey"
            android:value="key_live_czdCPU0qw7ahewzpy4R3k" />
      <meta-data
            android:name="io.branch.sdk.BranchKey.test"
            android:value="key_test_arwBJR1Fy5nddBwkFZL7B" />
      <meta-data
            android:name="io.branch.sdk.TestMode"
            android:value="true" />
      <!-- END: SUPERBRAINS BRANCH -->
      <!-- END: Code for Branch.io deeplink-->

In the main.dart file I have added this while initializing the app.

  await FlutterBranchSdk.init(
    useTestKey:
        flavor == Flavor.superbrains || flavor == Flavor.superbrains_stg,
    enableLogging: false,
    disableTracking: false,
  );
  FlutterBranchSdk.validateSDKIntegration();

While running the app in dev flavor I am getting this error.

Screenshot 2024-05-20 at 11 03 46 AM
Exception has occurred.
PlatformException (PlatformException(error, String resource ID #0x0, null, android.content.res.Resources$NotFoundException: String resource ID #0x0
    at android.content.res.Resources.getText(Resources.java:453)
    at android.content.res.Resources.getString(Resources.java:546)
    at io.branch.referral.BranchUtil.readBranchKey(BranchUtil.java:112)
    at io.branch.referral.Branch.getAutoInstance(Branch.java:384)
    at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.setupBranch(FlutterBranchSdkPlugin.java:393)
    at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.onMethodCall(FlutterBranchSdkPlugin.java:247)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
))

In the debug console I am getting this error message.

I/BranchSDK( 6677): enableTestMode has been changed. It now uses the test key but will not log or randomize the device IDs. If you wish to enable logging, please invoke enableLogging. If you wish to simulate installs, please see add a Test Device (https://help.branch.io/using-branch/docs/adding-test-devices) then reset your test device's data (https://help.branch.io/using-branch/docs/adding-test-devices#section-resetting-your-test-device-data).
E/rbrain.user.dev( 6677): Invalid ID 0x00000000.
E/MethodChannel#flutter_branch_sdk/message( 6677): Failed to handle method call
E/MethodChannel#flutter_branch_sdk/message( 6677): android.content.res.Resources$NotFoundException: String resource ID #0x0
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.content.res.Resources.getText(Resources.java:453)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.content.res.Resources.getString(Resources.java:546)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.branch.referral.BranchUtil.readBranchKey(BranchUtil.java:112)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.branch.referral.Branch.getAutoInstance(Branch.java:384)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.setupBranch(FlutterBranchSdkPlugin.java:393)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.onMethodCall(FlutterBranchSdkPlugin.java:247)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.os.Handler.handleCallback(Handler.java:942)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at android.app.ActivityThread.main(ActivityThread.java:7872)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#flutter_branch_sdk/message( 6677):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Can you please help me out what is the issue here and how to fix it? We have the upgraded plan and I raised a ticket on Friday, 17 May, 2024 but I have yet to recieve any reply back from Branch.io in my email. The ticket case number is 00386737.

RodrigoSMarques commented 5 months ago

@RodrigoSMarques I tried using only one app in Branch.io as you suggested. I have three flavors dev - Flavor.superbrains_dev, stg - Flavor.superbrains_stg, prod - Flavor.superbrains

This is my configuration in Android Manifest. [Not original keys & link]

      <!-- START: SUPERBRAINS BRANCH -->
      <!-- Branch App Links - SUPERBRAINS Live App -->
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
                    android:host="d3ksadwf1.app.link"
                    android:scheme="https" />
        <data
                    android:host="ddsa3kwf1-alternate.app.link"
                    android:scheme="https" />
      </intent-filter>
      <!-- Branch App Links - SUPERBRAINS Test App -->
      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
                    android:host="d3axaakf1.test-app.link"
                    android:scheme="https" />
        <data
                    android:host="d3sadwkf1-alternate.test-app.link"
                    android:scheme="https" />
      </intent-filter>
      <meta-data
            android:name="io.branch.sdk.BranchKey"
            android:value="key_live_czdCPU0qw7ahewzpy4R3k" />
      <meta-data
            android:name="io.branch.sdk.BranchKey.test"
            android:value="key_test_arwBJR1Fy5nddBwkFZL7B" />
      <meta-data
            android:name="io.branch.sdk.TestMode"
            android:value="true" />
      <!-- END: SUPERBRAINS BRANCH -->
      <!-- END: Code for Branch.io deeplink-->

In the main.dart file I have added this while initializing the app.

  await FlutterBranchSdk.init(
    useTestKey:
        flavor == Flavor.superbrains || flavor == Flavor.superbrains_stg,
    enableLogging: false,
    disableTracking: false,
  );
  FlutterBranchSdk.validateSDKIntegration();

While running the app in dev flavor I am getting this error. Screenshot 2024-05-20 at 11 03 46 AM

Exception has occurred.
PlatformException (PlatformException(error, String resource ID #0x0, null, android.content.res.Resources$NotFoundException: String resource ID #0x0
  at android.content.res.Resources.getText(Resources.java:453)
  at android.content.res.Resources.getString(Resources.java:546)
  at io.branch.referral.BranchUtil.readBranchKey(BranchUtil.java:112)
  at io.branch.referral.Branch.getAutoInstance(Branch.java:384)
  at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.setupBranch(FlutterBranchSdkPlugin.java:393)
  at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.onMethodCall(FlutterBranchSdkPlugin.java:247)
  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
  at android.os.Handler.handleCallback(Handler.java:942)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loopOnce(Looper.java:201)
  at android.os.Looper.loop(Looper.java:288)
  at android.app.ActivityThread.main(ActivityThread.java:7872)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
))

In the debug console I am getting this error message.

I/BranchSDK( 6677): enableTestMode has been changed. It now uses the test key but will not log or randomize the device IDs. If you wish to enable logging, please invoke enableLogging. If you wish to simulate installs, please see add a Test Device (https://help.branch.io/using-branch/docs/adding-test-devices) then reset your test device's data (https://help.branch.io/using-branch/docs/adding-test-devices#section-resetting-your-test-device-data).
E/rbrain.user.dev( 6677): Invalid ID 0x00000000.
E/MethodChannel#flutter_branch_sdk/message( 6677): Failed to handle method call
E/MethodChannel#flutter_branch_sdk/message( 6677): android.content.res.Resources$NotFoundException: String resource ID #0x0
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.content.res.Resources.getText(Resources.java:453)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.content.res.Resources.getString(Resources.java:546)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.branch.referral.BranchUtil.readBranchKey(BranchUtil.java:112)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.branch.referral.Branch.getAutoInstance(Branch.java:384)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.setupBranch(FlutterBranchSdkPlugin.java:393)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.onMethodCall(FlutterBranchSdkPlugin.java:247)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.os.Handler.handleCallback(Handler.java:942)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at android.app.ActivityThread.main(ActivityThread.java:7872)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#flutter_branch_sdk/message( 6677):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Can you please help me out what is the issue here and how to fix it? We have the upgraded plan and I raised a ticket on Friday, 17 May, 2024 but I have yet to recieve any reply back from Branch.io in my email. The ticket case number is 00386737.

The Tag

<intent-filter android:autoVerify="true"> 

must be between <activity>and </activity>.

<meta-data
            android:name="io.branch.sdk.BranchKey" 

and

<meta-data
            android:name="io.branch.sdk.BranchKey.test" 

must be outside <activity> and inside <application> </application>

Sample here

You can verify?

MarufHassanPietech commented 5 months ago

Thank you. I took the reference you provided above and it worked.

krishnatejakanchi commented 5 months ago

@RodrigoSMarques , we have app with 3 different bundle identifiers for 3 flavors. So using single app in branch.io is not working for us

RodrigoSMarques commented 5 months ago

@RodrigoSMarques , we have app with 3 different bundle identifiers for 3 flavors. So using single app in branch.io is not working for us

As I had previously reported.

This is a configuration question for the Branch SDK and not the plugin.

This plugin calls the SDK functions.

I suggest you open an issue directly with Branch.

iOS: https://github.com/BranchMetrics/ios-branch-deep-linking-attribution Android: https://github.com/BranchMetrics/android-branch-deep-linking-attribution Or open a support ticket for Branch at the link

You can also research how to have different INFO.PLIST on iOS, according to flavor, as each flavor needs to have different branch keys and different app links.

RodrigoSMarques commented 4 months ago

Closed. No activity in the last 14 days. If necessary open again.