-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add plugin for Android lifecycle in embedding. #2129
Add plugin for Android lifecycle in embedding. #2129
Conversation
packages/flutter_android_lifecycle/android/gradle/wrapper/gradle-wrapper.properties
Outdated
Show resolved
Hide resolved
| # adding or updating assets for this project. | ||
| plugin: | ||
| androidPackage: com.example.flutter_android_lifecycle | ||
| pluginClass: FlutterAndroidLifecyclePlugin |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
...le/android/app/src/main/java/com/example/flutter_android_lifecycle_example/MainActivity.java
Outdated
Show resolved
Hide resolved
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:flutter_android_lifecycle/flutter_android_lifecycle.dart'; | ||
|
|
||
| void main() { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
...oid/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java
Outdated
Show resolved
Hide resolved
|
@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? |
|
@amirh it looks like we're going to have a chicken/egg problem here with PR merges. This failure is from this PR: 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? |
...oid/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java
Show resolved
Hide resolved
| @@ -0,0 +1,122 @@ | |||
| { | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/ | |||
There was a problem hiding this comment.
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.
|
Consider removing the images from the PR. I know the tool generates a bunch of stuff that isn't really needed in some cases. |
|
@blasten which images? |
|
There are a few under |
|
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: |
|
@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)) { |
There was a problem hiding this comment.
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?)
|
Closing in favor of #2168 |
Add plugin for Android lifecycle in embedding.
Embedding side:
flutter/engine#12715