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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a2134..8b8b696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ## 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] +- Add support to Dart v3.0.0 [#52](https://github.com/PostHog/posthog-flutter/pull/52) ## 3.1.0 diff --git a/android/build.gradle b/android/build.gradle index 17a9e09..8b8ff7b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,39 +1,50 @@ -group 'com.posthog.posthog_flutter' -version '1.0-SNAPSHOT' - buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:7.4.2' } } 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 f378d56..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-5.4.1-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 1d4eef5..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,34 +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.BasePayload; -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 { @@ -38,6 +35,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()); @@ -73,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 @@ -308,19 +305,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