From cecf17e826bcb6eb5fe45427fbfb19ae40881ab1 Mon Sep 17 00:00:00 2001 From: Andy Goldberg Date: Thu, 6 Jul 2023 23:00:46 -0700 Subject: [PATCH 1/6] eliminated Flutter compiler warnings updated Gradle Wrapper version, Android Tools plugin version, and edited .java file to eliminate the compiler warnings --- android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../posthog_flutter/PosthogFlutterPlugin.java | 29 +++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 3bd0c25..fdc7779 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:7.4.2' } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index f378d56..d2b2f26 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip diff --git a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java index 1d4eef5..1ec0ea7 100644 --- a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java +++ b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java @@ -15,7 +15,13 @@ import com.posthog.android.Properties; import com.posthog.android.Options; import com.posthog.android.Middleware; +import com.posthog.android.payloads.AliasPayload; import com.posthog.android.payloads.BasePayload; +import com.posthog.android.payloads.CapturePayload; +import com.posthog.android.payloads.GroupPayload; +import com.posthog.android.payloads.IdentifyPayload; +import com.posthog.android.payloads.ScreenPayload; + import static com.posthog.android.PostHog.LogLevel; import java.util.LinkedHashMap; @@ -38,6 +44,7 @@ public class PosthogFlutterPlugin implements MethodCallHandler, FlutterPlugin { static HashMap appendToContextMiddleware; /** Plugin registration. */ + @SuppressWarnings("deprecation") public static void registerWith(PluginRegistry.Registrar registrar) { final PosthogFlutterPlugin instance = new PosthogFlutterPlugin(); instance.setupChannels(registrar.context(), registrar.messenger()); @@ -86,9 +93,22 @@ public void intercept(Chain chain) { } BasePayload payload = chain.payload(); - BasePayload newPayload = payload.toBuilder() - .context(appendToContextMiddleware) - .build(); +// BasePayload newPayload = payload.toBuilder() +// .context(appendToContextMiddleware) +// .build(); + BasePayload newPayload = null; + // great opportunity to use Sealed Classes and ensure a comprehensive check + if (payload instanceof AliasPayload) { + newPayload = ((AliasPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); + } else if (payload instanceof CapturePayload) { + newPayload = ((CapturePayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); + } else if (payload instanceof GroupPayload) { + newPayload = ((GroupPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); + } else if (payload instanceof IdentifyPayload) { + newPayload = ((IdentifyPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); + } else if (payload instanceof ScreenPayload) { + newPayload = ((ScreenPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); + } chain.proceed(newPayload); } catch (Exception e) { @@ -309,6 +329,7 @@ private Options buildOptions(HashMap optionsData) { return options; } + /* // Merges [newMap] into [original], *not* preserving [original] // keys (deep) in case of conflicts. private static Map deepMerge(Map original, Map newMap) { @@ -323,4 +344,6 @@ private static Map deepMerge(Map original, Map newMap) { } return original; } + */ + } From 55906f658a47ef0970088302eadb0807e923ed3b Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 10 Oct 2023 09:23:38 +0200 Subject: [PATCH 2/6] Update tooling to latest versions --- android/build.gradle | 31 +++++++++++----- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../posthog_flutter/PosthogFlutterPlugin.java | 37 ++----------------- example/android/app/build.gradle | 30 ++++++++++----- example/android/build.gradle | 6 +-- example/android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- 7 files changed, 50 insertions(+), 61 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 61d5c3f..8b8ff7b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,10 +1,7 @@ -group 'com.posthog.posthog_flutter' -version '1.0-SNAPSHOT' - buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { @@ -15,25 +12,39 @@ buildscript { rootProject.allprojects { repositories { google() - jcenter() - maven { url 'https://jitpack.io' } + mavenCentral() } } apply plugin: 'com.android.library' android { - compileSdkVersion 28 + compileSdk 33 + + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'com.posthog.posthog_flutter' + } defaultConfig { - minSdkVersion 16 - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + minSdkVersion 19 + + ndk { + // Flutter does not currently support building for x86 Android (See Issue 9253). + abiFilters("armeabi-v7a", "x86_64", "arm64-v8a") + } } + lintOptions { disable 'InvalidPackage' } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + dependencies { - implementation 'com.posthog.android:posthog:2.0.3' + api 'com.posthog.android:posthog:2.0.3' } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index d2b2f26..3a8b7ec 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip diff --git a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java index 1ec0ea7..3db305e 100644 --- a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java +++ b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java @@ -93,22 +93,9 @@ public void intercept(Chain chain) { } BasePayload payload = chain.payload(); -// BasePayload newPayload = payload.toBuilder() -// .context(appendToContextMiddleware) -// .build(); - BasePayload newPayload = null; - // great opportunity to use Sealed Classes and ensure a comprehensive check - if (payload instanceof AliasPayload) { - newPayload = ((AliasPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); - } else if (payload instanceof CapturePayload) { - newPayload = ((CapturePayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); - } else if (payload instanceof GroupPayload) { - newPayload = ((GroupPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); - } else if (payload instanceof IdentifyPayload) { - newPayload = ((IdentifyPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); - } else if (payload instanceof ScreenPayload) { - newPayload = ((ScreenPayload.Builder) payload.toBuilder()).context(appendToContextMiddleware).build(); - } + BasePayload newPayload = payload.toBuilder() + .context(appendToContextMiddleware) + .build(); chain.proceed(newPayload); } catch (Exception e) { @@ -328,22 +315,4 @@ private Options buildOptions(HashMap optionsData) { Options options = new Options(); return options; } - - /* - // Merges [newMap] into [original], *not* preserving [original] - // keys (deep) in case of conflicts. - private static Map deepMerge(Map original, Map newMap) { - for (Object key : newMap.keySet()) { - if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { - Map originalChild = (Map) original.get(key); - Map newChild = (Map) newMap.get(key); - original.put(key, deepMerge(originalChild, newChild)); - } else { - original.put(key, newMap.get(key)); - } - } - return original; - } - */ - } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 022b24f..621e2d5 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,9 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdk 33 + + namespace 'com.posthog.posthog_flutter_example' lintOptions { disable 'InvalidPackage' @@ -34,11 +36,14 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.posthog.posthog_flutter_example" - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 19 versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + + ndk { + // Flutter does not currently support building for x86 Android (See Issue 9253). + abiFilters("armeabi-v7a", "x86_64", "arm64-v8a") + } } buildTypes { @@ -48,14 +53,19 @@ android { signingConfig signingConfigs.debug } } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + lintOptions { + // workaround if using AGP 4.0 on release mode + // https://github.com/flutter/flutter/issues/58247 + checkReleaseBuilds false + } } flutter { source '../..' } - -dependencies { - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' -} diff --git a/example/android/build.gradle b/example/android/build.gradle index 59d227f..0822484 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,18 +1,18 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:7.4.2' } } allprojects { repositories { google() - jcenter() + mavenCentral() } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 38c8d45..8e4c009 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true +# remove after migrating to Android SDK v3 android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 939efa2..068cdb2 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip From 29dfccfeec75c9fa73cd84080e0e269ab60913e5 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 10 Oct 2023 09:25:19 +0200 Subject: [PATCH 3/6] fix imports --- .../posthog_flutter/PosthogFlutterPlugin.java | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java index 3db305e..56f83f8 100644 --- a/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java +++ b/android/src/main/java/com/posthog/posthog_flutter/PosthogFlutterPlugin.java @@ -1,40 +1,31 @@ package com.posthog.posthog_flutter; -import androidx.annotation.NonNull; +import static com.posthog.android.PostHog.LogLevel; -import android.app.Activity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; +import androidx.annotation.NonNull; + +import com.posthog.android.Middleware; +import com.posthog.android.Options; import com.posthog.android.PostHog; -import com.posthog.android.PostHogContext; import com.posthog.android.Properties; -import com.posthog.android.Options; -import com.posthog.android.Middleware; -import com.posthog.android.payloads.AliasPayload; import com.posthog.android.payloads.BasePayload; -import com.posthog.android.payloads.CapturePayload; -import com.posthog.android.payloads.GroupPayload; -import com.posthog.android.payloads.IdentifyPayload; -import com.posthog.android.payloads.ScreenPayload; - -import static com.posthog.android.PostHog.LogLevel; -import java.util.LinkedHashMap; import java.util.HashMap; import java.util.Map; +import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry; -import io.flutter.embedding.engine.plugins.FlutterPlugin; /** PosthogFlutterPlugin */ public class PosthogFlutterPlugin implements MethodCallHandler, FlutterPlugin { @@ -80,8 +71,7 @@ private void setupChannels(Context applicationContext, BinaryMessenger messenger posthogBuilder.logLevel(LogLevel.DEBUG); } - // Here we build a middleware that just appends data to the current context - // using the [deepMerge] strategy. + // Here we build a middleware that just appends data to the current context. posthogBuilder.middleware( new Middleware() { @Override From a322208ba2ebdfada446e9f70517195b7b3bcb84 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 2 Nov 2023 15:57:42 +0100 Subject: [PATCH 4/6] set java version --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3d4dd4..80e5436 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,8 @@ on: branches: - master pull_request: + paths-ignore: + - "**/*.md" # Publish using custom workflow jobs: @@ -11,6 +13,13 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 + + - name: 'Set up Java' + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: 'temurin' + - uses: dart-lang/setup-dart@v1 - uses: subosito/flutter-action@v2 with: From 2dbf2d74fb86b2e8c5e9293d8430d750b69ecfda Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 2 Nov 2023 16:07:39 +0100 Subject: [PATCH 5/6] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a2134..3d78612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.2.0 -- Add support to Dart v3.0.0 (#52)[https://github.com/PostHog/posthog-flutter/pull/52] +- Add support to Dart v3.0.0 [#52](https://github.com/PostHog/posthog-flutter/pull/52) ## 3.1.0 From 50fe00c669a5303798c90e859a7472d174c10f6e Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 2 Nov 2023 16:10:01 +0100 Subject: [PATCH 6/6] add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d78612..8b8b696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- Migrate to Java 8 and minSdkVersion 19 [#54](https://github.com/PostHog/posthog-flutter/pull/54) + ## 3.2.0 - Add support to Dart v3.0.0 [#52](https://github.com/PostHog/posthog-flutter/pull/52)