diff --git a/android/build.gradle b/android/build.gradle index abcc973..6619741 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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")) { @@ -36,6 +42,9 @@ android { } defaultConfig { minSdkVersion 16 + + buildConfigField 'String', 'SDK_VERSION', "\"${PUBLISH_VERSION}\"" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } lintOptions { diff --git a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt index 53ee199..ae1e9ba 100644 --- a/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt +++ b/android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt @@ -64,6 +64,10 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { "init" -> { val configuration = getConfiguration(call) amplitude = Amplitude(configuration) + + // Set library + amplitude.add(FlutterLibraryPlugin()) + call.argument("logLevel")?.let { amplitude.logger.logMode = Logger.LogMode.valueOf(it.uppercase()) } diff --git a/android/src/main/kotlin/com/amplitude/amplitude_flutter/FlutterLibraryPlugin.kt b/android/src/main/kotlin/com/amplitude/amplitude_flutter/FlutterLibraryPlugin.kt new file mode 100644 index 0000000..8f15a30 --- /dev/null +++ b/android/src/main/kotlin/com/amplitude/amplitude_flutter/FlutterLibraryPlugin.kt @@ -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) + } +} diff --git a/lib/constants.dart b/lib/constants.dart index bc9480e..a11aab5 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -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"; diff --git a/lib/events/base_event.dart b/lib/events/base_event.dart index 075a893..da027be 100644 --- a/lib/events/base_event.dart +++ b/lib/events/base_event.dart @@ -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'; @@ -38,7 +37,7 @@ class BaseEvent extends EventOptions { String? appSetId, String? androidId, String? language, - String library = "${Constants.packageName}/${Constants.packageVersion}", + String? library, String? ip, Plan? plan, IngestionMetadata? ingestionMetadata, diff --git a/release.config.js b/release.config.js index 28bebf7..7b5b234 100644 --- a/release.config.js +++ b/release.config.js @@ -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 + }, ] } ], diff --git a/test/amplitude_test.dart b/test/amplitude_test.dart index 32d8771..34c7724 100644 --- a/test/amplitude_test.dart +++ b/test/amplitude_test.dart @@ -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;