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

Conversation

@ajmalk
Copy link
Contributor

@ajmalk ajmalk commented Jul 12, 2021

  • call getContext instead of getActivity in FlutterActivityAndFragmentDelegate.onCreateView

Fixes: flutter/flutter#85326

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Android Activity.
- call getContext instead of getActivity in FlutterActivityAndFragmentDelegate.onCreateView
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

could we add a test to verify that onCreateView doesn't call getActivity, but instead getContext?

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 12, 2021

could we add a test to verify that onCreateView doesn't call getActivity, but instead getContext?

Yes I was looking into this but I can't seem to get the tests to run locally. Are there any docs to help with that? Currently I'm getting:

There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [FlutterActivityAndFragmentDelegateTest.java]
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
        at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
        at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
        at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
        at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: FlutterActivityAndFragmentDelegateTest.java
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.junit.internal.Classes.getClass(Classes.java:42)
        at org.junit.internal.Classes.getClass(Classes.java:27)
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:98)
        ... 4 more

When I try to run testing/run_tests.py --type=java --java-filter=FlutterActivityAndFragmentDelegateTest.java

@blasten
Copy link

blasten commented Jul 12, 2021

what about testing/run_tests.py --type=java --java-filter=io.flutter.embedding.android.FlutterActivityAndFragmentDelegateTest?

@blasten
Copy link

blasten commented Jul 12, 2021

actually, I'm seeing the same issue. cc @dnfield Is this related to recent changes?

@dnfield
Copy link
Contributor

dnfield commented Jul 12, 2021

Make sure you build the target(s) first - run_tests.py used to do some of that for you but doesn't anymore because it messed up things on LUCI.

/cc @zanderso fyi

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 12, 2021

Do you mean just run ninja -C out/android_debug_unopt? I did that and it built fine. Tried running it again and it says "no work to do".

@dnfield
Copy link
Contributor

dnfield commented Jul 12, 2021

Make sure to also build the roboletric_tests target there - ninja -C out/android_debug_unopt robolectric_tests.

Since the test script doesn't build that target for you anymore, we should really add it to the default Android build rule, at least for the case of armv7 debug.

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 12, 2021

The build ran correctly (I think). But I'm still the same java.lang.IllegalArgumentException when I try to run the test.

@dnfield
Copy link
Contributor

dnfield commented Jul 12, 2021

That error sounds like there's something missing in the way the test is set up or decorated.

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

It's not a test I added fwiw. Are you saying it's broken at head? Are unit test not run by your presubmit? What should I do?

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

I am able to run these tests at head :/. They run on the Linux android debug shard

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

Oh hmm. I'm trying to run on mac. I suppose I could try and run it on linux. Do you think that will help?

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

I ran it locally on mac.

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

Hmm. I think some sort of instructions for setup would be helpful.

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

This works for me from the src directory:

git -C flutter fetch upstream
git -C flutter merge upstream/master
gclient sync
./flutter/tools/gn --android --unopt --runtime-mode=debug
ninja -C out/android_debug_unopt
./flutter/testing/run_tests.py --type-java

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

The only thing I can think of - this is all using JDK 1.8. For better or worse we use your system JDK and do not vend a JDK with the engine repo. I think JDK 1.9 should work, but I'm willing to bet JDK 1.10/11/12 will not.

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

So for me, javac -version shows javac 1.8.0_221

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

ok I changed the java version and that finally worked! Thanks. I'll send over the unit tests soon.

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

For reference I ran this from the src dir:

./flutter/tools/gn --android --unopt --runtime-mode=debug
ninja -C out/android_debug_unopt
ninja -C out/android_debug_unopt robolectric_tests
./flutter/testing/run_tests.py --type=java --java-filter=io.flutter.embedding.android.FlutterActivityAndFragmentDelegateTest

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

And I had to install Java 8 by downloading it from the oracle website and manually editing my PATH.

@ajmalk
Copy link
Contributor Author

ajmalk commented Jul 13, 2021

Ok. I made sure there's test coverage. I opted to modify an existing test instead of adding a new one since that seemed appropriate in this case. Should I add/modify docs somewhere so people know FlutterFragment can be used without an Activity? Or is too niche a use case?

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM.

If you want to update docs that's fine, but AFAIK this use case was always intended to be supported and this code just slipped through the cracks.

@dnfield
Copy link
Contributor

dnfield commented Jul 13, 2021

Waiting to apply the label on review from @blasten

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

@blasten blasten added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 13, 2021
@fluttergithubbot fluttergithubbot merged commit 317166d into flutter:master Jul 14, 2021
zanderso added a commit that referenced this pull request Jul 14, 2021
…ed to an Android Activity. (#27332)"

This reverts commit 317166d.
zanderso added a commit that referenced this pull request Jul 14, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 14, 2021
dnfield added a commit to dnfield/engine that referenced this pull request Jul 14, 2021
moffatman pushed a commit to moffatman/engine that referenced this pull request Aug 5, 2021
moffatman pushed a commit to moffatman/engine that referenced this pull request Aug 5, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes needs tests platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Call getContext instead of getActivity in FlutterActivityAndFragmentDelegate.onCreateView

4 participants