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

chore: set library by plugin #175

Merged
merged 3 commits into from
Mar 5, 2024
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 android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ rootProject.allprojects {
}
}

ext {
PUBLISH_VERSION = '4.0.0-beta.0'
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
buildFeatures.buildConfig true

compileSdkVersion 34
// Condition for namespace compatibility in AGP 8
if (project.android.hasProperty("namespace")) {
Expand All @@ -36,6 +42,9 @@ android {
}
defaultConfig {
minSdkVersion 16

buildConfigField 'String', 'SDK_VERSION', "\"${PUBLISH_VERSION}\""

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
"init" -> {
val configuration = getConfiguration(call)
amplitude = Amplitude(configuration)

// Set library
amplitude.add(FlutterLibraryPlugin())

call.argument<String>("logLevel")?.let {
amplitude.logger.logMode = Logger.LogMode.valueOf(it.uppercase())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.amplitude.amplitude_flutter

import com.amplitude.core.Amplitude
import com.amplitude.core.events.BaseEvent
import com.amplitude.core.platform.Plugin
import com.amplitude.amplitude_flutter.BuildConfig

class FlutterLibraryPlugin: Plugin {
override val type: Plugin.Type = Plugin.Type.Before
override lateinit var amplitude: Amplitude

companion object {
const val SDK_LIBRARY = "amplitude-flutter"
const val SDK_VERSION = BuildConfig.SDK_VERSION
}

override fun execute(event: BaseEvent): BaseEvent? {
event.library = "$SDK_LIBRARY/$SDK_VERSION"
return super.execute(event)
}
}
2 changes: 0 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class Constants {
static const packageName = "amplitude-flutter";
static const packageVersion = "3.16.1";
static const identify_event = "\$identify";
static const group_identify_event = "\$groupidentify";
static const revenue_event = "revenue_amount";
Expand Down
3 changes: 1 addition & 2 deletions lib/events/base_event.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:amplitude_flutter/constants.dart';
import 'package:amplitude_flutter/events/plan.dart';
import 'event_options.dart';
import 'ingestion_metadata.dart';
Expand Down Expand Up @@ -38,7 +37,7 @@ class BaseEvent extends EventOptions {
String? appSetId,
String? androidId,
String? language,
String library = "${Constants.packageName}/${Constants.packageVersion}",
String? library,
justin-fiedler marked this conversation as resolved.
Show resolved Hide resolved
String? ip,
Plan? plan,
IngestionMetadata? ingestionMetadata,
Expand Down
14 changes: 14 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ module.exports = {
],
"countMatches": true
},
{
"files": ["android/build.gradle"],
"from": "PUBLISH_VERSION = \'.*\'",
"to": "PUBLISH_VERSION = \'${nextRelease.version}\'",
"results": [
{
"file": "android/build.gradle",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
},
]
}
],
Expand Down
1 change: 0 additions & 1 deletion test/amplitude_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void main() {
final testEvent = BaseEvent(eventType: "testEvent");
final testEventMap = {
"event_type": "testEvent",
"library": "${Constants.packageName}/${Constants.packageVersion}",
"attempts": 0,
};
final testPrice = 3.99;
Expand Down
Loading