Skip to content

Commit

Permalink
Add FlutterPlayStoreSplitApplication to v2 embedding (flutter#29241)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryQian authored Oct 27, 2021
1 parent 2cf993f commit 9208b7a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/Flutt
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSplashView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ android_java_sources = [
"io/flutter/embedding/android/FlutterFragment.java",
"io/flutter/embedding/android/FlutterFragmentActivity.java",
"io/flutter/embedding/android/FlutterImageView.java",
"io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java",
"io/flutter/embedding/android/FlutterSplashView.java",
"io/flutter/embedding/android/FlutterSurfaceView.java",
"io/flutter/embedding/android/FlutterTextureView.java",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2013 The Flutter 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.embedding.android;

import androidx.annotation.CallSuper;
import com.google.android.play.core.splitcompat.SplitCompatApplication;
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager;

// TODO(garyq): Add a note about deferred components automatically adding this to manifest via
// manifest variable injection once it is implemented.
/**
* Flutter's extension of {@link SplitCompatApplication} that injects a {@link
* PlayStoreDeferredComponentManager} with {@link FlutterInjector} to enable Split AOT Flutter apps.
*
* <p>To use this class, either have your custom application class extend
* FlutterPlayStoreSplitApplication or use it directly in the app's AndroidManifest.xml by adding
* the following line:
*
* <pre>{@code
* <manifest
* ...
* <application
* android:name="io.flutter.embedding.android.FlutterPlayStoreSplitApplication"
* ...>
* </application>
* </manifest>
* }</pre>
*
* This class is meant to be used with the Google Play store. Custom non-play store applications do
* not need to extend {@link com.google.android.play.core.splitcompat.SplitCompatApplication} and
* should inject a custom {@link
* io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager} implementation like so:
*
* <pre>{@code
* FlutterInjector.setInstance(
* new FlutterInjector.Builder().setDeferredComponentManager(yourCustomManager).build());
* }</pre>
*/
public class FlutterPlayStoreSplitApplication extends SplitCompatApplication {
@Override
@CallSuper
public void onCreate() {
super.onCreate();
// Create and inject a PlayStoreDeferredComponentManager, which is the default manager for
// interacting with the Google Play Store.
PlayStoreDeferredComponentManager deferredComponentManager =
new PlayStoreDeferredComponentManager(this, null);
FlutterInjector.setInstance(
new FlutterInjector.Builder()
.setDeferredComponentManager(deferredComponentManager)
.build());
}
}

0 comments on commit 9208b7a

Please sign in to comment.