Skip to content

[firebase_core] v2 embedding API #274

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

Merged
merged 16 commits into from
Oct 22, 2019
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
4 changes: 4 additions & 0 deletions packages/firebase_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.1

* Support the v2 Android embedding.

## 0.4.0+9

* Update documentation to reflect new repository location.
Expand Down
26 changes: 26 additions & 0 deletions packages/firebase_core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ android {
}
}

// TODO(bparrishMines): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "1.1.1"
api "android.arch.lifecycle:runtime:$lifecycle_version"
api "android.arch.lifecycle:common:$lifecycle_version"
api "android.arch.lifecycle:common-java8:$lifecycle_version"
}
}
}
}

apply from: file("./user-agent.gradle")
1 change: 0 additions & 1 deletion packages/firebase_core/android/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,65 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.firebase.core;

import android.content.Context;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import java.lang.String;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FirebaseCorePlugin implements MethodCallHandler {
/**
* Flutter plugin implementation controlling the entrypoint for the Firebase SDK.
*
* <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes.
*/
public class FirebaseCorePlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
private static final String CHANNEL_NAME = "plugins.flutter.io/firebase_core";

private final Context context;
private MethodChannel channel;
private Context applicationContext;

/**
* Registers a plugin with the v1 embedding api {@code io.flutter.plugin.common}.
*
* <p>Calling this will register the plugin with the passed registrar. However plugins initialized
* this way won't react to changes in activity or context, unlike {@link FirebaseCorePlugin}.
*/
public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_core");
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
channel.setMethodCallHandler(new FirebaseCorePlugin(registrar.context()));
}

private FirebaseCorePlugin(Context context) {
this.context = context;
/**
* Default Constructor.
*
* <p>Use this constructor in an add to app scenario to gracefully handle activity and context
* changes.
*/
public FirebaseCorePlugin() {}

private FirebaseCorePlugin(Context applicationContext) {
this.applicationContext = applicationContext;
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
applicationContext = binding.getApplicationContext();
channel = new MethodChannel(binding.getFlutterEngine().getDartExecutor(), CHANNEL_NAME);
channel.setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
applicationContext = null;
}

private Map<String, Object> asMap(FirebaseApp app) {
Expand All @@ -48,7 +78,7 @@ private Map<String, Object> asMap(FirebaseApp app) {
}

@Override
public void onMethodCall(MethodCall call, final Result result) {
public void onMethodCall(MethodCall call, final MethodChannel.Result result) {
switch (call.method) {
case "FirebaseApp#configure":
{
Expand All @@ -65,14 +95,14 @@ public void onMethodCall(MethodCall call, final Result result) {
.setProjectId(optionsMap.get("projectID"))
.setStorageBucket(optionsMap.get("storageBucket"))
.build();
FirebaseApp.initializeApp(context, options, name);
FirebaseApp.initializeApp(applicationContext, options, name);
result.success(null);
break;
}
case "FirebaseApp#allApps":
{
List<Map<String, Object>> apps = new ArrayList<>();
for (FirebaseApp app : FirebaseApp.getApps(context)) {
for (FirebaseApp app : FirebaseApp.getApps(applicationContext)) {
apps.add(asMap(app));
}
result.success(apps);
Expand Down
5 changes: 3 additions & 2 deletions packages/firebase_core/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
2 changes: 0 additions & 2 deletions packages/firebase_core/example/android/app/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.firebase.core;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import io.flutter.plugins.firebasecoreexample.EmbeddingV1Activity;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.firebase.core;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import io.flutter.plugins.firebasecoreexample.MainActivity;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="firebase_core_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name=".EmbeddingV1Activity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
Expand All @@ -17,6 +17,13 @@
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
</activity>
<activity
android:name=".MainActivity"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.flutter.plugins.firebasecoreexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbeddingV1Activity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.flutter.plugins.firebasecoreexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.firebase.core.FirebaseCorePlugin;

public class MainActivity extends FlutterActivity {
// TODO(bparrishMines): Remove this once v2 of GeneratedPluginRegistrant rolls to stable. https://github.com/flutter/flutter/issues/42694
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new FirebaseCorePlugin());
}
}
3 changes: 3 additions & 0 deletions packages/firebase_core/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
4 changes: 4 additions & 0 deletions packages/firebase_core/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
cupertino_icons: ^0.1.0

dev_dependencies:
e2e: ^0.2.1
flutter_test:
sdk: flutter

Expand All @@ -22,3 +23,6 @@ dev_dependencies:
# The following section is specific to Flutter.
flutter:
uses-material-design: true

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
7 changes: 5 additions & 2 deletions packages/firebase_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Core, enabling connecting to multiple
Firebase apps.
author: Flutter Team <[email protected]>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_core
version: 0.4.0+9
version: 0.4.1

flutter:
plugin:
Expand All @@ -17,9 +17,12 @@ dependencies:
meta: "^1.0.5"

dev_dependencies:
e2e: ^0.2.1
flutter_driver:
sdk: flutter
flutter_test:
sdk: flutter

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
flutter: ">=1.9.1+hotfix.5 <2.0.0"
31 changes: 31 additions & 0 deletions packages/firebase_core/test/firebase_core_e2e.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:e2e/e2e.dart';

void main() {
E2EWidgetsFlutterBinding.ensureInitialized();

testWidgets('configure', (WidgetTester tester) async {
await FirebaseApp.configure(
name: 'foo',
options: const FirebaseOptions(
googleAppID: '1:297855924061:ios:c6de2b69b03a5be8',
gcmSenderID: '297855924061',
apiKey: 'AIzaSyBq6mcufFXfyqr79uELCiqM_O_1-G72PVU',
),
);

final List<FirebaseApp> apps = await FirebaseApp.allApps();
expect(apps, hasLength(1));

final FirebaseOptions options = await apps[0].options;

expect(options.apiKey, 'AIzaSyBq6mcufFXfyqr79uELCiqM_O_1-G72PVU');
expect(options.gcmSenderID, '297855924061');
expect(options.googleAppID, '1:297855924061:ios:c6de2b69b03a5be8');
});
}