Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@matthew-carroll
Copy link
Contributor

Add plugin for Android lifecycle in embedding.

Embedding side:
flutter/engine#12715

# adding or updating assets for this project.
plugin:
androidPackage: com.example.flutter_android_lifecycle
pluginClass: FlutterAndroidLifecyclePlugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - make sure the apps using this plugin can build and run for iOS.
Note that we should be soon able to delete all ios code from this plugin once flutter/flutter#39659 is resolved and we migrate to the new pubspec schema, but that will have to wait for the next stable release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a process for verifying that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build and run the example app on iOS (or any app the depends on the plugin)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amirh @blasten I got the following error when attempting to build and run the iOS app. Do either of you happen to know a remedy?

Downloading ios tools...                                            6.2s
Downloading ios-profile tools...                                    4.4s
Downloading ios-release tools...                                   17.3s
Launching lib/main.dart on iPhone Xʀ in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           30.7s
Finished with error: ProcessException: Process exited abnormally:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Failed to install the requested application
The application's Info.plist does not contain CFBundleVersion.
Ensure your bundle contains a CFBundleVersion with a valid semantic version number.
  Command: /usr/bin/xcrun simctl install 0B543D29-BF06-4FF5-951E-2B98933F2403 [redacted]/flutter_plugins/packages/flutter_android_lifecycle/example/build/ios/iphonesimulator/Runner.app

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks similar to flutter/flutter#34477 cc @jmagman

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_android_lifecycle/flutter_android_lifecycle.dart';

void main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this file

static const MethodChannel _channel =
const MethodChannel('flutter_android_lifecycle');

static Future<String> get platformVersion async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd definitely remove this, I'm curious if we can publish a pub package with no Dart code (worth trying). If not we should figure out what's the minimal contents we need here (an empty file?)

void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we leave just this line (and make the Android code use getLifecycle) we should have our e2e test.

Copy link
Contributor

@collinjackson collinjackson Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty close to being the e2e test you want but it's actually just a unit test that ships with the flutter create plugin template. It will need to call ensureInitialized on a compatible binding to be runnable with FlutterRunner or flutter drive. We could add a TODO to that effect if we want to get it landed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widget_test.dart will require main.dart, which currently requires flutter_android_lifecycle.dart. Do you know which subset of these files we want to keep?

@matthew-carroll
Copy link
Contributor Author

@amirh @collinjackson it looks like the largest remaining issue is whether or not we should delete various files. Can you let me know what to keep/delete as soon as possible?

@matthew-carroll
Copy link
Contributor Author

@amirh it looks like we're going to have a chicken/egg problem here with PR merges. This failure is from this PR:

/tmp/cirrus-ci-build/packages/flutter_android_lifecycle/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:14: error: cannot find symbol
    if (!(reference instanceof HiddenLifecycleReference)) {
                               ^
  symbol:   class HiddenLifecycleReference
  location: class FlutterLifecycleAdapter
/tmp/cirrus-ci-build/packages/flutter_android_lifecycle/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:20: error: cannot find symbol
    this.lifecycle = ((HiddenLifecycleReference) reference).getLifecycle();
                       ^
  symbol:   class HiddenLifecycleReference
  location: class FlutterLifecycleAdapter
2 errors
FAILURE: Build failed with an exception.

If we merge the embedding change first, we can solve the above issue, but everyone on master who needs Lifecycle for a plugin will be broken until we merge this. In the opposite direction, we would have to choose to merge with CI failures here, and then merge the embedding once we have published this package.

Thoughts?

@@ -0,0 +1,122 @@
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this ios/ directory can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know for sure that we can delete it? The android_intent plugin seems to include an /ios directory:
https://github.com/flutter/plugins/tree/master/packages/android_intent

@@ -0,0 +1,37 @@
.idea/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment about the ios/ directory.

@blasten
Copy link

blasten commented Oct 4, 2019

Consider removing the images from the PR. I know the tool generates a bunch of stuff that isn't really needed in some cases.

@matthew-carroll
Copy link
Contributor Author

@blasten which images?

@blasten
Copy link

blasten commented Oct 4, 2019

There are a few under flutter_android_lifecycle/example/android/app/src/main/res/....

@matthew-carroll
Copy link
Contributor Author

Those all look to be ic_launcher images. Did you want me to remove all but one? We can't remove them all I don't think, because I believe Android requires an icon launcher image. I'm not sure if Android will allow us to use one for all resolutions or not.

The android_intent plugin seems to contain those same images:
https://github.com/flutter/plugins/tree/master/packages/android_intent/example/android/app/src/main/res

@blasten
Copy link

blasten commented Oct 4, 2019

@amirh would probably know best, then. I heard that in general we don't want to commit binaries to source trees.

@NonNull private final Lifecycle lifecycle;

public FlutterLifecycleAdapter(@NonNull Object reference) {
if (!(reference instanceof HiddenLifecycleReference)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that this is going to be compiled with a Flutter Engine version that does not have the HiddenLifecycleReference (e.g if a migrated plugin is used with today's stable).

I think we should use reflection to access this type? (can we make sure proguard doesn't rename it?)

@matthew-carroll
Copy link
Contributor Author

@amirh @blasten I just pushed a change that uses reflection instead of compile-time references for the hidden lifecycle.

@amirh
Copy link
Contributor

amirh commented Oct 8, 2019

Closing in favor of #2168

@amirh amirh closed this Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants