Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tooling to latest version #54

Merged
merged 8 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ on:
branches:
- master
pull_request:
paths-ignore:
- "**/*.md"

# Publish using custom workflow
jobs:
build:
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:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
33 changes: 22 additions & 11 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -38,6 +35,7 @@ public class PosthogFlutterPlugin implements MethodCallHandler, FlutterPlugin {
static HashMap<String, Object> appendToContextMiddleware;

/** Plugin registration. */
@SuppressWarnings("deprecation")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrate to the new plugin

public static void registerWith(PluginRegistry.Registrar registrar) {
final PosthogFlutterPlugin instance = new PosthogFlutterPlugin();
instance.setupChannels(registrar.context(), registrar.messenger());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -308,19 +305,4 @@ private Options buildOptions(HashMap<String, Object> 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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method was not used

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;
}
}
30 changes: 20 additions & 10 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand All @@ -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'
}
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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()
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
# remove after migrating to Android SDK v3
android.enableJetifier=true
3 changes: 1 addition & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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