Skip to content

Commit f7029ac

Browse files
committed
set library via method channel
1 parent d0e5f07 commit f7029ac

File tree

10 files changed

+19
-56
lines changed

10 files changed

+19
-56
lines changed

android/build.gradle

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ rootProject.allprojects {
2121
}
2222
}
2323

24-
ext {
25-
PUBLISH_VERSION = '4.0.0-beta.0'
26-
}
27-
2824
apply plugin: 'com.android.library'
2925
apply plugin: 'kotlin-android'
3026

3127
android {
32-
buildFeatures.buildConfig true
33-
3428
compileSdkVersion 34
3529
// Condition for namespace compatibility in AGP 8
3630
if (project.android.hasProperty("namespace")) {
@@ -42,9 +36,6 @@ android {
4236
}
4337
defaultConfig {
4438
minSdkVersion 16
45-
46-
buildConfigField 'String', 'SDK_VERSION', "\"${PUBLISH_VERSION}\""
47-
4839
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
4940
}
5041
lintOptions {

android/src/main/kotlin/com/amplitude/amplitude_flutter/AmplitudeFlutterPlugin.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
2828

2929
private lateinit var channel: MethodChannel
3030

31-
3231
companion object {
3332
private const val methodChannelName = "amplitude_flutter"
3433
}
@@ -66,7 +65,7 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
6665
amplitude = Amplitude(configuration)
6766

6867
// Set library
69-
amplitude.add(FlutterLibraryPlugin())
68+
amplitude.add(FlutterLibraryPlugin(call.argument<String>("library")!!))
7069

7170
call.argument<String>("logLevel")?.let {
7271
amplitude.logger.logMode = Logger.LogMode.valueOf(it.uppercase())

android/src/main/kotlin/com/amplitude/amplitude_flutter/FlutterLibraryPlugin.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@ package com.amplitude.amplitude_flutter
33
import com.amplitude.core.Amplitude
44
import com.amplitude.core.events.BaseEvent
55
import com.amplitude.core.platform.Plugin
6-
import com.amplitude.amplitude_flutter.BuildConfig
76

8-
class FlutterLibraryPlugin: Plugin {
7+
class FlutterLibraryPlugin(val library: String): Plugin {
98
override val type: Plugin.Type = Plugin.Type.Before
109
override lateinit var amplitude: Amplitude
1110

12-
companion object {
13-
const val SDK_LIBRARY = "amplitude-flutter"
14-
const val SDK_VERSION = BuildConfig.SDK_VERSION
15-
}
16-
1711
override fun execute(event: BaseEvent): BaseEvent? {
18-
event.library = "$SDK_LIBRARY/$SDK_VERSION"
12+
event.library = library
1913
return super.execute(event)
2014
}
2115
}

ios/Classes/FlutterLibraryPlugin.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import Foundation
22
import AmplitudeSwift
33

44
class FlutterLibraryPlugin: BeforePlugin {
5-
static let sdkLibrary = "amplitude-flutter"
6-
// Version is managed automatically by semantic-release in release.config.js, please don't change it manually
7-
static let sdkVersion = "4.0.0-beta.0"
5+
let library: String
6+
7+
init(library: String) {
8+
self.library = library
9+
}
810

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

1214
return event
1315
}

ios/Classes/SwiftAmplitudeFlutterPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import AmplitudeSwift
2727
}
2828

2929
// Set library
30-
amplitude?.add(plugin: FlutterLibraryPlugin())
30+
amplitude?.add(plugin: FlutterLibraryPlugin(library: args["library"] as! String))
3131

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

ios/amplitude_flutter.podspec

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#
22
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
33
#
4-
5-
amplitude_version = "4.0.0-beta.0" # Version is managed automatically by semantic-release, please don't change it manually
6-
74
Pod::Spec.new do |s|
85
s.name = 'amplitude_flutter'
9-
s.version = amplitude_version
6+
s.version = '0.0.1'
107
s.summary = 'A new flutter plugin project.'
118
s.homepage = 'http://example.com'
129
s.license = { :file => '../LICENSE' }

lib/configuration.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Configuration {
9393
'useAdvertisingIdForDeviceId': useAdvertisingIdForDeviceId,
9494
'useAppSetIdForDeviceId': useAppSetIdForDeviceId,
9595
'appVersion': appVersion,
96+
// This field doesn't belong to Configuration
97+
// Pass it for FlutterLibraryPlugin
98+
'library': "${Constants.packageName}/${Constants.packageVersion}"
9699
};
97100
}
98101
}

lib/constants.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Constants {
2+
static const packageName = "amplitude-flutter";
3+
static const packageVersion = "3.16.1";
24
static const identify_event = "\$identify";
35
static const group_identify_event = "\$groupidentify";
46
static const revenue_event = "revenue_amount";

release.config.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,6 @@ module.exports = {
6363
],
6464
"countMatches": true
6565
},
66-
{
67-
"files": ["android/build.gradle"],
68-
"from": "PUBLISH_VERSION = \'.*\'",
69-
"to": "PUBLISH_VERSION = \'${nextRelease.version}\'",
70-
"results": [
71-
{
72-
"file": "android/build.gradle",
73-
"hasChanged": true,
74-
"numMatches": 1,
75-
"numReplacements": 1
76-
}
77-
],
78-
"countMatches": true
79-
},
80-
{
81-
"files": ["ios/Classes/FlutterLibraryPlugin.swift"],
82-
"from": "static let sdkVersion = \".*\"",
83-
"to": "static let sdkVersion = \"${nextRelease.version}\"",
84-
"results": [
85-
{
86-
"file": "ios/Classes/FlutterLibraryPlugin.swift",
87-
"hasChanged": true,
88-
"numMatches": 1,
89-
"numReplacements": 1
90-
}
91-
],
92-
"countMatches": true
93-
},
9466
]
9567
}
9668
],

test/amplitude_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ void main() {
8383
"useAdvertisingIdForDeviceId": false,
8484
"useAppSetIdForDeviceId": false,
8585
"appVersion": null,
86+
// This field doesn't belong to Configuration
87+
// Pass it for FlutterLibraryPlugin
88+
"library": "${Constants.packageName}/${Constants.packageVersion}"
8689
};
8790
final testEvent = BaseEvent(eventType: "testEvent");
8891
final testEventMap = {

0 commit comments

Comments
 (0)