From 70afdbe4a781dc166307a4f77ed3ae700c5f0825 Mon Sep 17 00:00:00 2001
From: Rodrigo de Souza Marques <rodrigosmarques@gmail.com>
Date: Sat, 28 Dec 2024 14:59:58 -0300
Subject: [PATCH 1/5] Migrate Gradle to declarative plugins block

---
 android/build.gradle              | 32 +++++++++---------
 example/android/app/build.gradle  | 54 +++++++++++--------------------
 example/android/build.gradle      | 13 --------
 example/android/gradle.properties |  2 +-
 example/android/settings.gradle   | 30 ++++++++++++-----
 5 files changed, 57 insertions(+), 74 deletions(-)

diff --git a/android/build.gradle b/android/build.gradle
index f3575a81..02442350 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,5 +1,5 @@
-group 'br.com.rsmarques.flutter_branch_sdk'
-version '1.0'
+group = 'br.com.rsmarques.flutter_branch_sdk'
+version = '1.0'
 
 def getPackageVersion() {
     def props = new Properties()
@@ -15,7 +15,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:8.1.4'
+        classpath("com.android.tools.build:gradle:8.2.2")
     }
 }
 
@@ -34,27 +34,27 @@ android {
         namespace 'br.com.rsmarques.flutter_branch_sdk'
     }
 
+    compileSdk 35
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_11
+        targetCompatibility JavaVersion.VERSION_11
+    }
+
     buildFeatures {
         buildConfig = true
     }
-
-    compileSdk 35
-
     defaultConfig {
         minSdkVersion 21
         buildConfigField("String", "FBRANCH_VERSION", "\"${getPackageVersion()}\"")
     }
 
-    compileOptions {
-        sourceCompatibility JavaVersion.VERSION_11
-        targetCompatibility JavaVersion.VERSION_11
+    dependencies {
+        implementation 'io.branch.sdk.android:library:5.15.+'
+        implementation 'com.google.android.gms:play-services-ads-identifier:18.2.0'
+        implementation 'androidx.lifecycle:lifecycle-runtime:2.8.7'
+        implementation 'androidx.browser:browser:1.8.0'
+        implementation "store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0"
     }
 }
 
-dependencies {
-    implementation 'io.branch.sdk.android:library:5.15.+'
-    implementation 'com.google.android.gms:play-services-ads-identifier:18.2.0'
-    implementation 'androidx.lifecycle:lifecycle-runtime:2.8.7'
-    implementation 'androidx.browser:browser:1.8.0'
-    implementation "store.galaxy.samsung.installreferrer:samsung_galaxystore_install_referrer:4.0.0"
-}
\ No newline at end of file
diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle
index 278cd09b..191d3c54 100644
--- a/example/android/app/build.gradle
+++ b/example/android/app/build.gradle
@@ -1,51 +1,33 @@
-def localProperties = new Properties()
-def localPropertiesFile = rootProject.file('local.properties')
-if (localPropertiesFile.exists()) {
-    localPropertiesFile.withReader('UTF-8') { reader ->
-        localProperties.load(reader)
-    }
-}
-
-def flutterRoot = localProperties.getProperty('flutter.sdk')
-if (flutterRoot == null) {
-    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
-}
-
-def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
-if (flutterVersionCode == null) {
-    flutterVersionCode = '1'
-}
-
-def flutterVersionName = localProperties.getProperty('flutter.versionName')
-if (flutterVersionName == null) {
-    flutterVersionName = '1.0'
+plugins {
+    id "com.android.application"
+    id "kotlin-android"
+    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
+    id "dev.flutter.flutter-gradle-plugin"
 }
 
-apply plugin: 'com.android.application'
-apply plugin: 'kotlin-android'
-apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
-
 android {
     namespace 'br.com.rsmarques.flutter_branch_sdk_example'
-    defaultConfig {
-        compileSdk flutter.compileSdkVersion
-    }
-    ndkVersion flutter.ndkVersion
+    compileSdk = flutter.compileSdkVersion
+    ndkVersion = flutter.ndkVersion
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_11
         targetCompatibility JavaVersion.VERSION_11
     }
-    
+
+    kotlinOptions {
+        jvmTarget = JavaVersion.VERSION_11
+    }
+
     defaultConfig {
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
         applicationId "br.com.rsmarques.flutter_branch_sdk_example"
-        // You can update the following values to match your application needs. 
-        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
-        minSdkVersion 21
-        targetSdkVersion flutter.targetSdkVersion
-        versionCode flutterVersionCode.toInteger()
-        versionName flutterVersionName
+        // You can update the following values to match your application needs.
+        // For more information, see: https://flutter.dev/to/review-gradle-config.
+        minSdk = flutter.minSdkVersion
+        targetSdk = flutter.targetSdkVersion
+        versionCode = flutter.versionCode
+        versionName = flutter.versionName
         multiDexEnabled true
     }
 
diff --git a/example/android/build.gradle b/example/android/build.gradle
index 94a816d9..bc157bd1 100644
--- a/example/android/build.gradle
+++ b/example/android/build.gradle
@@ -1,16 +1,3 @@
-buildscript {
-    ext.kotlin_version = '1.7.10'
-    repositories {
-        google()
-        mavenCentral()
-    }
-
-    dependencies {
-        classpath 'com.android.tools.build:gradle:8.2.1'
-        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-    }
-}
-
 allprojects {
     repositories {
         google()
diff --git a/example/android/gradle.properties b/example/android/gradle.properties
index 7723ef5b..28a11535 100644
--- a/example/android/gradle.properties
+++ b/example/android/gradle.properties
@@ -1,4 +1,4 @@
-org.gradle.jvmargs=-Xmx1536M
+org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
 android.useAndroidX=true
 android.enableJetifier=true
 android.defaults.buildfeatures.buildconfig=true
diff --git a/example/android/settings.gradle b/example/android/settings.gradle
index 33f0745d..da6d3f25 100644
--- a/example/android/settings.gradle
+++ b/example/android/settings.gradle
@@ -1,11 +1,25 @@
-include ':app'
+pluginManagement {
+    def flutterSdkPath = {
+        def properties = new Properties()
+        file("local.properties").withInputStream { properties.load(it) }
+        def flutterSdkPath = properties.getProperty("flutter.sdk")
+        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
+        return flutterSdkPath
+    }()
 
-def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
-def properties = new Properties()
+    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
 
-assert localPropertiesFile.exists()
-localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
+    repositories {
+        google()
+        mavenCentral()
+        gradlePluginPortal()
+    }
+}
 
-def flutterSdkPath = properties.getProperty("flutter.sdk")
-assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
-apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
+plugins {
+    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
+    id "com.android.application" version "8.2.2" apply false
+    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
+}
+
+include ":app"

From 4ba85208968fc2f0cf11a80fa9cdac8278337fdb Mon Sep 17 00:00:00 2001
From: Junglee-Faisal <mohd.faisal@jungleegames.com>
Date: Wed, 15 Jan 2025 07:17:44 +0000
Subject: [PATCH 2/5] fixed: reply already sent and a possible ANR

---
 .../MethodResultWrapper.java                   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/android/src/main/java/br/com/rsmarques/flutter_branch_sdk/MethodResultWrapper.java b/android/src/main/java/br/com/rsmarques/flutter_branch_sdk/MethodResultWrapper.java
index 3bc513ce..30f3a979 100644
--- a/android/src/main/java/br/com/rsmarques/flutter_branch_sdk/MethodResultWrapper.java
+++ b/android/src/main/java/br/com/rsmarques/flutter_branch_sdk/MethodResultWrapper.java
@@ -9,14 +9,26 @@
 public class MethodResultWrapper implements MethodChannel.Result {
     private final MethodChannel.Result methodResult;
     private final Handler handler;
+    private boolean called;
 
     MethodResultWrapper(MethodChannel.Result result) {
         methodResult = result;
         handler = new Handler(Looper.getMainLooper());
     }
 
+    private synchronized boolean checkNotCalled() {
+        if (called) {
+            return false;
+        }
+        called = true;
+        return true;
+    }
+
     @Override
     public void success(final Object result) {
+        if (!checkNotCalled()) {
+            return;
+        }
         handler.post(
                 new Runnable() {
                     @Override
@@ -33,6 +45,9 @@ public void run() {
     @Override
     public void error(
             final String errorCode, final String errorMessage, final Object errorDetails) {
+        if (!checkNotCalled()) {
+            return;
+        }
         handler.post(
                 new Runnable() {
                     @Override
@@ -48,6 +63,9 @@ public void run() {
 
     @Override
     public void notImplemented() {
+        if (!checkNotCalled()) {
+            return;
+        }
         handler.post(
                 new Runnable() {
                     @Override

From 8c3f30a3f60f5f92564a94db5c426751b0e81477 Mon Sep 17 00:00:00 2001
From: Rodrigo de Souza Marques <rodrigosmarques@gmail.com>
Date: Wed, 15 Jan 2025 10:40:36 -0300
Subject: [PATCH 3/5] Update pubspec.yaml

---
 pubspec.yaml | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/pubspec.yaml b/pubspec.yaml
index 19f94373..ac6ff4d8 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -43,4 +43,11 @@ flutter:
         pluginClass: FlutterBranchSdkPlugin
       web:
         pluginClass: FlutterBranchSdkWeb
-        fileName: src/flutter_branch_sdk_web.dart
\ No newline at end of file
+        fileName: src/flutter_branch_sdk_web.dart
+
+  topics:
+    - deeplink
+    - app-links
+    - universal-links
+    - custom-url-schemes
+    - web-to-app
\ No newline at end of file

From cd040ab668bb828fc0451fdb58838de46a636f36 Mon Sep 17 00:00:00 2001
From: Rodrigo de Souza Marques <rodrigosmarques@gmail.com>
Date: Wed, 15 Jan 2025 10:44:10 -0300
Subject: [PATCH 4/5] Update pubspec.yaml

---
 pubspec.yaml | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pubspec.yaml b/pubspec.yaml
index ac6ff4d8..97bb137c 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -45,9 +45,9 @@ flutter:
         pluginClass: FlutterBranchSdkWeb
         fileName: src/flutter_branch_sdk_web.dart
 
-  topics:
-    - deeplink
-    - app-links
-    - universal-links
-    - custom-url-schemes
-    - web-to-app
\ No newline at end of file
+topics:
+  - deeplink
+  - app-links
+  - universal-links
+  - custom-url-schemes
+  - web-to-app
\ No newline at end of file

From 91f25437363554e4a7bd8407c0ab422dbaab8663 Mon Sep 17 00:00:00 2001
From: Rodrigo de Souza Marques <rodrigosmarques@gmail.com>
Date: Thu, 16 Jan 2025 22:16:17 -0300
Subject: [PATCH 5/5] Release 8.3.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

### ⚠️ BREAKING CHANGE
* Minimum required Dart SDK version 3.3.0 (Flutter 3.19.0 - 15/02/2024)

### 🐛 Bug Fixes
* Fix issue #410: "reply already sent and a possible ANR". Tks @Junglee-Faisal

### 🎉 Features
* Migrated Gradle to declarative plugins block
---
 CHANGELOG.md         | 10 ++++++++++
 example/pubspec.lock |  2 +-
 pubspec.yaml         |  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a06d1713..88d131f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+## 8.3.2
+### ⚠️ BREAKING CHANGE
+* Minimum required Dart SDK version 3.3.0 (Flutter 3.19.0 - 15/02/2024)
+
+### 🐛 Bug Fixes
+* Fix issue #410: "reply already sent and a possible ANR". Tks @Junglee-Faisal
+
+### 🎉 Features
+* Migrated Gradle to declarative plugins block
+
 ## 8.3.1
 ### ⚠️ BREAKING CHANGE
 * Minimum required Dart SDK version 3.3.0 (Flutter 3.19.0 - 15/02/2024)
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 8827b94b..902119bb 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -84,7 +84,7 @@ packages:
       path: ".."
       relative: true
     source: path
-    version: "8.3.1"
+    version: "8.3.2"
   flutter_lints:
     dependency: "direct dev"
     description:
diff --git a/pubspec.yaml b/pubspec.yaml
index 97bb137c..3f679c26 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
 name: flutter_branch_sdk
 description: "Flutter Plugin for create deep link using Brach SDK (https://branch.io). This plugin provides a cross-platform (iOS, Android, Web)."
-version: 8.3.1
+version: 8.3.2
 repository: https://github.com/RodrigoSMarques/flutter_branch_sdk
 
 environment: