Skip to content

Commit

Permalink
set library via method channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Mar 6, 2024
1 parent d0e5f07 commit f7029ac
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 56 deletions.
9 changes: 0 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ 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 @@ -42,9 +36,6 @@ 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 @@ -28,7 +28,6 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

private lateinit var channel: MethodChannel


companion object {
private const val methodChannelName = "amplitude_flutter"
}
Expand Down Expand Up @@ -66,7 +65,7 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
amplitude = Amplitude(configuration)

// Set library
amplitude.add(FlutterLibraryPlugin())
amplitude.add(FlutterLibraryPlugin(call.argument<String>("library")!!))

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
Expand Up @@ -3,19 +3,13 @@ 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 {
class FlutterLibraryPlugin(val library: String): 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"
event.library = library
return super.execute(event)
}
}
10 changes: 6 additions & 4 deletions ios/Classes/FlutterLibraryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import Foundation
import AmplitudeSwift

class FlutterLibraryPlugin: BeforePlugin {
static let sdkLibrary = "amplitude-flutter"
// Version is managed automatically by semantic-release in release.config.js, please don't change it manually
static let sdkVersion = "4.0.0-beta.0"
let library: String

init(library: String) {
self.library = library
}

override func execute(event: BaseEvent) -> BaseEvent? {
event.library = "\(FlutterLibraryPlugin.sdkLibrary)/\(FlutterLibraryPlugin.sdkVersion)"
event.library = library

return event
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/SwiftAmplitudeFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import AmplitudeSwift
}

// Set library
amplitude?.add(plugin: FlutterLibraryPlugin())
amplitude?.add(plugin: FlutterLibraryPlugin(library: args["library"] as! String))

amplitude?.logger?.debug(message: "Amplitude has been successfully initialized.")

Expand Down
5 changes: 1 addition & 4 deletions ios/amplitude_flutter.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

amplitude_version = "4.0.0-beta.0" # Version is managed automatically by semantic-release, please don't change it manually

Pod::Spec.new do |s|
s.name = 'amplitude_flutter'
s.version = amplitude_version
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
Expand Down
3 changes: 3 additions & 0 deletions lib/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Configuration {
'useAdvertisingIdForDeviceId': useAdvertisingIdForDeviceId,
'useAppSetIdForDeviceId': useAppSetIdForDeviceId,
'appVersion': appVersion,
// This field doesn't belong to Configuration
// Pass it for FlutterLibraryPlugin
'library': "${Constants.packageName}/${Constants.packageVersion}"
};
}
}
2 changes: 2 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
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
28 changes: 0 additions & 28 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,6 @@ 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
},
{
"files": ["ios/Classes/FlutterLibraryPlugin.swift"],
"from": "static let sdkVersion = \".*\"",
"to": "static let sdkVersion = \"${nextRelease.version}\"",
"results": [
{
"file": "ios/Classes/FlutterLibraryPlugin.swift",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
},
]
}
],
Expand Down
3 changes: 3 additions & 0 deletions test/amplitude_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void main() {
"useAdvertisingIdForDeviceId": false,
"useAppSetIdForDeviceId": false,
"appVersion": null,
// This field doesn't belong to Configuration
// Pass it for FlutterLibraryPlugin
"library": "${Constants.packageName}/${Constants.packageVersion}"
};
final testEvent = BaseEvent(eventType: "testEvent");
final testEventMap = {
Expand Down

0 comments on commit f7029ac

Please sign in to comment.