|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +package io.flutter.app; |
| 6 | + |
| 7 | +import androidx.annotation.CallSuper; |
| 8 | +import com.google.android.play.core.splitcompat.SplitCompatApplication; |
| 9 | +import io.flutter.FlutterInjector; |
| 10 | +import io.flutter.embedding.engine.dynamicfeatures.PlayStoreDynamicFeatureManager; |
| 11 | + |
| 12 | +/** |
| 13 | + * Flutter's extension of {@link SplitCompatApplication} that injects a {@link |
| 14 | + * PlayStoreDynamicFeatureManager} with {@link FlutterInjector} to enable Split AOT Flutter apps. |
| 15 | + * |
| 16 | + * <p>To use this class, either have your custom application class extend |
| 17 | + * FlutterPlayStoreSplitApplication or use it directly in the app's AndroidManifest.xml by adding |
| 18 | + * the following line: |
| 19 | + * |
| 20 | + * <pre>{@code |
| 21 | + * <manifest |
| 22 | + * ... |
| 23 | + * <application |
| 24 | + * android:name="io.flutter.app.FlutterPlayStoreSplitApplication" |
| 25 | + * ...> |
| 26 | + * </application> |
| 27 | + * </manifest> |
| 28 | + * }</pre> |
| 29 | + * |
| 30 | + * This class is meant to be used with the Google Play store. Custom non-play store applications do |
| 31 | + * not need to extend SplitCompatApplication and should inject a custom {@link |
| 32 | + * io.flutter.embedding.engine.dynamicfeatures.DynamicFeatureManager} implementation like so: |
| 33 | + * |
| 34 | + * <pre>{@code |
| 35 | + * FlutterInjector.setInstance( |
| 36 | + * new FlutterInjector.Builder().setDynamicFeatureManager(yourCustomManager).build()); |
| 37 | + * }</pre> |
| 38 | + */ |
| 39 | +public class FlutterPlayStoreSplitApplication extends SplitCompatApplication { |
| 40 | + @Override |
| 41 | + @CallSuper |
| 42 | + public void onCreate() { |
| 43 | + super.onCreate(); |
| 44 | + // Create and inject a PlayStoreDynamicFeatureManager, which is the default manager for |
| 45 | + // interacting with the Google Play Store. |
| 46 | + PlayStoreDynamicFeatureManager dynamicFeatureManager = |
| 47 | + new PlayStoreDynamicFeatureManager(this, null); |
| 48 | + FlutterInjector.setInstance( |
| 49 | + new FlutterInjector.Builder().setDynamicFeatureManager(dynamicFeatureManager).build()); |
| 50 | + } |
| 51 | +} |
0 commit comments