Skip to content

Commit

Permalink
Auto retrieve version to report user agent (firebase#1748)
Browse files Browse the repository at this point in the history
* Auto retrieve version to report user agent
  • Loading branch information
kroikie authored Jun 17, 2019
1 parent 2985671 commit c359a68
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ GeneratedPluginRegistrant.m
GeneratedPluginRegistrant.java
build/
.flutter-plugins

1 change: 1 addition & 0 deletions packages/firebase_remote_config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ios/Classes/UserAgent.h
4 changes: 4 additions & 0 deletions packages/firebase_remote_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0+3

* Automatically use version from pubspec.yaml when reporting usage to Firebase.

## 0.2.0+2

* Add missing template type parameter to `invokeMethod` calls.
Expand Down
3 changes: 3 additions & 0 deletions packages/firebase_remote_config/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ android {
}
dependencies {
api 'com.google.firebase:firebase-config:16.4.1'
implementation 'com.google.firebase:firebase-common:16.1.0'
implementation 'androidx.annotation:annotation:1.0.0'
}
}

apply from: file("./user-agent.gradle")
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.firebase.firebaseremoteconfig">
<application>
<service android:name="com.google.firebase.components.ComponentDiscoveryService">
<meta-data android:name="com.google.firebase.components:io.flutter.plugins.firebase.firebaseremoteconfig.FlutterFirebaseAppRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.flutter.plugins.firebase.firebaseremoteconfig;

import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import java.util.Collections;
import java.util.List;

public class FlutterFirebaseAppRegistrar implements ComponentRegistrar {
@Override
public List<Component<?>> getComponents() {
return Collections.<Component<?>>singletonList(
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION));
}
}
22 changes: 22 additions & 0 deletions packages/firebase_remote_config/android/user-agent.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.regex.Matcher
import java.util.regex.Pattern

String libraryVersionName = "UNKNOWN"
String libraryName = "flutter-fire-rc"
File pubspec = new File(project.projectDir.parentFile, 'pubspec.yaml')

if (pubspec.exists()) {
String yaml = pubspec.text
// Using \s*['|"]?([^\n|'|"]*)['|"]? to extract version number.
Matcher versionMatcher = Pattern.compile("^version:\\s*['|\"]?([^\\n|'|\"]*)['|\"]?\$", Pattern.MULTILINE).matcher(yaml)
if (versionMatcher.find()) libraryVersionName = versionMatcher.group(1).replaceAll("\\+", "-")
}

android {
defaultConfig {
// BuildConfig.VERSION_NAME
buildConfigField 'String', 'LIBRARY_VERSION', "\"${libraryVersionName}\""
// BuildConfig.LIBRARY_NAME
buildConfigField 'String', 'LIBRARY_NAME', "\"${libraryName}\""
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "FirebaseRemoteConfigPlugin.h"
#import "UserAgent.h"

#import <Firebase/Firebase.h>

Expand All @@ -14,6 +15,11 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
binaryMessenger:[registrar messenger]];
FirebaseRemoteConfigPlugin *instance = [[FirebaseRemoteConfigPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];

SEL sel = NSSelectorFromString(@"registerLibrary:withVersion:");
if ([FIRApp respondsToSelector:sel]) {
[FIRApp performSelector:sel withObject:LIBRARY_NAME withObject:LIBRARY_VERSION];
}
}

- (instancetype)init {
Expand Down
11 changes: 11 additions & 0 deletions packages/firebase_remote_config/ios/firebase_remote_config.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

require 'yaml'
pubspec = YAML.load_file(File.join('..', 'pubspec.yaml'))
libraryVersion = pubspec['version'].gsub('+', '-')

Pod::Spec.new do |s|
s.name = 'firebase_remote_config'
s.version = '0.0.1'
Expand All @@ -18,5 +23,11 @@ Firebase Remote Config plugin for Flutter.
s.dependency 'Flutter'
s.dependency 'Firebase/RemoteConfig'
s.static_framework = true

s.prepare_command = <<-CMD
echo // Generated file, do not edit > Classes/UserAgent.h
echo "#define LIBRARY_VERSION @\\"#{libraryVersion}\\"" >> Classes/UserAgent.h
echo "#define LIBRARY_NAME @\\"flutter-fire-rc\\"" >> Classes/UserAgent.h
CMD
end

2 changes: 1 addition & 1 deletion packages/firebase_remote_config/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Remote Config. Update your application
re-releasing.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_remote_config
version: 0.2.0+2
version: 0.2.0+3

dependencies:
flutter:
Expand Down

0 comments on commit c359a68

Please sign in to comment.