flutter / gallery

Flutter Gallery was a resource to help developers evaluate and use Flutter
BSD 3-Clause "New" or "Revised" License
6.39k stars 1.55k forks source link

building gallery for Android with local engine fails #899

Closed mraleph closed 9 months ago

mraleph commented 3 years ago

(Note: assuming that https://github.com/flutter/gallery/pull/525 is landed. Otherwise you first need to apply that on top)

$ git clone https://github.com/flutter/gallery
$ cd gallery
$ flutter run -v --profile --local-engine android_profile_arm64
...
[   +2 ms] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:11: error:
package io.flutter.embedding.engine.plugins does not exist
[   +5 ms] import io.flutter.embedding.engine.plugins.FlutterPlugin;
[        ]                                           ^
[        ] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:12: error:
package io.flutter.plugin.common does not exist
[        ] import io.flutter.plugin.common.BinaryMessenger;
[        ]                                ^
[        ] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:13: error:
package io.flutter.plugin.common does not exist
[        ] import io.flutter.plugin.common.MethodCall;
[        ]                                ^
[        ] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:14: error:
package io.flutter.plugin.common does not exist
[        ] import io.flutter.plugin.common.MethodChannel;
[        ]                                ^
[        ] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:15: error:
package io.flutter.plugin.common.MethodChannel does not exist
[        ] import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
[        ]                                              ^
[        ] /usr/local/google/home/vegorov/.pub-cache/hosted/pub.dartlang.org/package_info-2.0.0/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java:16: error:
package io.flutter.plugin.common.MethodChannel does not exist
[        ] import io.flutter.plugin.common.MethodChannel.Result;
...

/cc @blasten

TahaTesser commented 3 years ago

Hi Thanks for filing the issue, took me while to setup the engine locallly but finally I've pulled your PR locally into clone Gallery repository when running in debug mode, I am not seeing any such error

taha@pop-os:~/Documents/gallery$ fm run --local-engine-src-path /home/taha/Code/engine/src  --local-engine=android_debug_unopt_arm64
Launching lib/main.dart on Redmi K20 Pro in debug mode...
Shrinking has been disabled for this build due to deferred components. Shrinking is not available for multi-apk applications.
This limitation is expected to be removed when Gradle plugin 4.2+ is available in Flutter.
Running Gradle task 'assembleDebug'...                             21.7s
āœ“  Built build/app/outputs/flutter-apk/app-debug.apk.
E/flutter (32246): [ERROR:flutter/shell/common/shell.cc(906)] Embedding reported invalid ViewportMetrics, ignoring update.
E/flutter (32246): physical_width: 0
E/flutter (32246): physical_height: 0
E/flutter (32246): device_pixel_ratio: 2.75
E/flutter (32246): [ERROR:flutter/shell/common/shell.cc(906)] Embedding reported invalid ViewportMetrics, ignoring update.
E/flutter (32246): physical_width: 0
E/flutter (32246): physical_height: 0
E/flutter (32246): device_pixel_ratio: 2.75
Syncing files to device Redmi K20 Pro...                         1,136ms

Flutter run key commands.
r Hot reload. šŸ”„šŸ”„šŸ”„
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

An Observatory debugger and profiler on Redmi K20 Pro is available at: http://127.0.0.1:45019/IMn7aQ3JrxQ=/
The Flutter DevTools debugger and profiler on Redmi K20 Pro is available at:
http://127.0.0.1:9100?uri=http%3A%2F%2F127.0.0.1%3A45019%2FIMn7aQ3JrxQ%3D%2F
flutter doctor -v ```console' [āœ“] Flutter (Channel master, 2.3.0-17.0.pre.397, on Pop!_OS 21.04 5.11.0-7614-generic, locale en_US.UTF-8) ā€¢ Flutter version 2.3.0-17.0.pre.397 at /home/taha/Code/flutter_master ā€¢ Upstream repository https://github.com/flutter/flutter.git ā€¢ Framework revision 03034e9e4a (9 hours ago), 2021-06-18 00:14:03 -0700 ā€¢ Engine revision ced58ef9c1 ā€¢ Dart version 2.14.0 (build 2.14.0-217.0.dev) [āœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ā€¢ Android SDK at /home/taha/Code/SDK ā€¢ Platform android-30, build-tools 30.0.3 ā€¢ ANDROID_HOME = /home/taha/Code/SDK ā€¢ Java binary at: /home/taha/Code/android-studio/jre/bin/java ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821) ā€¢ All Android licenses accepted. [āœ“] Chrome - develop for the web ā€¢ Chrome at google-chrome [āœ“] Linux toolchain - develop for Linux desktop ā€¢ Ubuntu clang version 12.0.0-1ubuntu1 ā€¢ cmake version 3.18.4 ā€¢ ninja version 1.8.2 ā€¢ pkg-config version 0.29.2 [āœ“] Android Studio (version 4.2) ā€¢ Android Studio at /home/taha/Code/android-studio ā€¢ Flutter plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/9212-flutter ā€¢ Dart plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/6351-dart ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821) [āœ“] VS Code (version 1.57.1) ā€¢ VS Code at /usr/share/code ā€¢ Flutter extension can be installed from: šŸ”Ø https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [āœ“] Connected device (3 available) ā€¢ Redmi K20 Pro (mobile) ā€¢ def0ad20 ā€¢ android-arm64 ā€¢ Android 10 (API 29) ā€¢ Linux (desktop) ā€¢ linux ā€¢ linux-x64 ā€¢ Pop!_OS 21.04 5.11.0-7614-generic ā€¢ Chrome (web) ā€¢ chrome ā€¢ web-javascript ā€¢ Google Chrome 91.0.4472.114 ā€¢ No issues found! ```

I couldn't run profile mode flutter_embedding_profile.pom wasn't found in the local engine out directory., Any ideas?

jason-simmons commented 3 years ago

As a workaround, try adding this to the subprojects section of Gallery's android/build.gradle:

    afterEvaluate {
        if (plugins.hasPlugin('com.android.library')) {
            dependencies {
                implementation "io.flutter:flutter_embedding_profile:+"
            }
        }
    }
mraleph commented 3 years ago

I couldn't run profile mode flutter_embedding_profile.pom wasn't found in the local engine out directory., Any ideas?

How did you build the profile engine? You need something like:

$ flutter/tools/gn --runtime-mode profile
$ ninja -C out/host_profile
$ flutter/tools/gn --runtime-mode profile --android --android-cpu arm64
$ ninja -C out/android_profile_arm64

As a workaround, try adding this to the subprojects section of Gallery's android/build.gradle:

Thanks @jason-simmons this indeed makes it build. Any idea why is this not part of the default template?

TahaTesser commented 3 years ago

Hi @mraleph Thank you for the details!

I can confirm the issue

logs ```console [ +576 ms] [ +655 ms] aot_android_asset_bundle: Complete [+1300 ms] [+1223 ms] Skipping target: android_aot_bundle_profile_android-arm64 [ ] [ ] Persisting file store [ ] [ +30 ms] Done persisting file store [ +99 ms] [ +47 ms] build succeeded. [ ] [ +25 ms] "flutter assemble" took 65,067ms. [ +199 ms] [ +257 ms] ensureAnalyticsSent: 251ms [ ] [ +9 ms] Running shutdown hooks [ ] [ ] Shutdown hooks complete [ +99 ms] [ +1 ms] exiting with code 0 [ +399 ms] > Task :app:packLibsflutterBuildProfile UP-TO-DATE [ ] > Task :package_info_plus:preBuild UP-TO-DATE [ ] > Task :package_info_plus:preDebugBuild UP-TO-DATE [ ] > Task :package_info_plus:processDebugJavaRes NO-SOURCE [ ] > Task :package_info_plus:bundleLibResDebug NO-SOURCE [ ] > Task :package_info_plus:compileDebugAidl NO-SOURCE [ ] > Task :package_info_plus:compileDebugRenderscript NO-SOURCE [ ] > Task :package_info_plus:generateDebugBuildConfig UP-TO-DATE [ ] > Task :package_info_plus:generateDebugResValues UP-TO-DATE [ ] > Task :package_info_plus:generateDebugResources UP-TO-DATE [ ] > Task :package_info_plus:packageDebugResources UP-TO-DATE [ +97 ms] > Task :package_info_plus:parseDebugLocalResources UP-TO-DATE [ ] > Task :package_info_plus:processDebugManifest UP-TO-DATE [ ] > Task :package_info_plus:javaPreCompileDebug UP-TO-DATE [ ] > Task :path_provider:preBuild UP-TO-DATE [ ] > Task :path_provider:preDebugBuild UP-TO-DATE [ ] > Task :path_provider:processDebugJavaRes NO-SOURCE [ ] > Task :path_provider:bundleLibResDebug NO-SOURCE [ ] > Task :path_provider:compileDebugAidl NO-SOURCE [ ] > Task :path_provider:compileDebugRenderscript NO-SOURCE [ ] > Task :path_provider:generateDebugBuildConfig UP-TO-DATE [ +3 ms] > Task :path_provider:generateDebugResValues UP-TO-DATE [ ] > Task :path_provider:generateDebugResources UP-TO-DATE [ ] > Task :path_provider:packageDebugResources UP-TO-DATE [ ] > Task :package_info_plus:generateDebugRFile [ ] > Task :path_provider:parseDebugLocalResources UP-TO-DATE [ +197 ms] > Task :package_info_plus:compileDebugJavaWithJavac FAILED [ ] Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. [ ] Use '--warning-mode all' to show the individual deprecation warnings. [ ] See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings [ ] 14 actionable tasks: 3 executed, 11 up-to-date [ +1 ms] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:11: error: package io.flutter.embedding.engine.plugins does not exist [ +2 ms] import io.flutter.embedding.engine.plugins.FlutterPlugin; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:12: error: package io.flutter.plugin.common does not exist [ ] import io.flutter.plugin.common.BinaryMessenger; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:13: error: package io.flutter.plugin.common does not exist [ ] import io.flutter.plugin.common.MethodCall; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:14: error: package io.flutter.plugin.common does not exist [ ] import io.flutter.plugin.common.MethodChannel; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:15: error: package io.flutter.plugin.common.MethodChannel does not exist [ +12 ms] import io.flutter.plugin.common.MethodChannel.MethodCallHandler; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:16: error: package io.flutter.plugin.common.MethodChannel does not exist [ +3 ms] import io.flutter.plugin.common.MethodChannel.Result; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:17: error: package io.flutter.plugin.common.PluginRegistry does not exist [ ] import io.flutter.plugin.common.PluginRegistry.Registrar; [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:22: error: cannot find symbol [ ] public class PackageInfoPlugin implements MethodCallHandler, FlutterPlugin { [ ] ^ [ ] symbol: class MethodCallHandler [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:22: error: cannot find symbol [ +9 ms] public class PackageInfoPlugin implements MethodCallHandler, FlutterPlugin { [ ] ^ [ +2 ms] symbol: class FlutterPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:24: error: cannot find symbol [ ] private MethodChannel methodChannel; [ ] ^ [ +1 ms] symbol: class MethodChannel [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:27: error: cannot find symbol [ ] public static void registerWith(Registrar registrar) { [ +4 ms] ^ [ ] symbol: class Registrar [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:33: error: cannot find symbol [ ] public void onAttachedToEngine(FlutterPluginBinding binding) { [ ] ^ [ ] symbol: class FlutterPluginBinding [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:37: error: cannot find symbol [ ] private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) { [ ] ^ [ ] symbol: class BinaryMessenger [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:44: error: cannot find symbol [ ] public void onDetachedFromEngine(FlutterPluginBinding binding) { [ +4 ms] ^ [ ] symbol: class FlutterPluginBinding [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:51: error: cannot find symbol [ ] public void onMethodCall(MethodCall call, Result result) { [ ] ^ [ ] symbol: class MethodCall [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:51: error: cannot find symbol [ ] public void onMethodCall(MethodCall call, Result result) { [ ] ^ [ ] symbol: class Result [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:32: error: method does not override or implement a method from a supertype [ +4 ms] @Override [ ] ^ [ +3 ms] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:39: error: cannot find symbol [ +4 ms] methodChannel = new MethodChannel(messenger, "dev.fluttercommunity.plus/package_info"); [ ] ^ [ ] symbol: class MethodChannel [ ] location: class PackageInfoPlugin [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:43: error: method does not override or implement a method from a supertype [ ] @Override [ ] ^ [ ] /home/taha/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.0.3/android/src/main/java/dev/fluttercommunity/plus/packageinfo/PackageInfoPlugin.ja va:50: error: method does not override or implement a method from a supertype [ ] @Override [ +4 ms] ^ [ ] 20 errors [ ] FAILURE: Build failed with an exception. [ ] * What went wrong: [ ] Execution failed for task ':package_info_plus:compileDebugJavaWithJavac'. [ ] > Compilation failed; see the compiler error output for details. [ ] * Try: [ ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. [ ] * Get more help at https://help.gradle.org [ ] BUILD FAILED in 1m 8s [ +370 ms] Running Gradle task 'assembleProfile'... (completed in 68.8s) [ +8 ms] Exception: Gradle task assembleProfile failed with exit code 1 [ +4 ms] "flutter run" took 69,998ms. [ +18 ms] #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) flutter/flutter#1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:671:9) flutter/flutter#2 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1126:27) flutter/flutter#3 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) flutter/flutter#4 CommandRunner.runCommand (package:args/command_runner.dart:196:13) flutter/flutter#5 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:284:9) flutter/flutter#6 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) flutter/flutter#7 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:232:5) flutter/flutter#8 run.. (package:flutter_tools/runner.dart:62:9) flutter/flutter#9 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) flutter/flutter#10 main (package:flutter_tools/executable.dart:91:3) [ +223 ms] ensureAnalyticsSent: 217ms [ +4 ms] Running shutdown hooks [ ] Shutdown hooks complete [ +1 ms] exiting with code 1 ```
flutter doctor -v ```console [āœ“] Flutter (Channel master, 2.3.0-17.0.pre.414, on Pop!_OS 21.04 5.11.0-7614-generic, locale en_US.UTF-8) ā€¢ Flutter version 2.3.0-17.0.pre.414 at /home/taha/Code/flutter_master ā€¢ Upstream repository https://github.com/flutter/flutter.git ā€¢ Framework revision 757c3add14 (9 hours ago), 2021-06-20 22:29:02 -0400 ā€¢ Engine revision 9520bb15b3 ā€¢ Dart version 2.14.0 (build 2.14.0-228.0.dev) [āœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ā€¢ Android SDK at /home/taha/Code/SDK ā€¢ Platform android-30, build-tools 30.0.3 ā€¢ ANDROID_HOME = /home/taha/Code/SDK ā€¢ Java binary at: /home/taha/Code/android-studio/jre/bin/java ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821) ā€¢ All Android licenses accepted. [āœ“] Chrome - develop for the web ā€¢ Chrome at google-chrome [āœ“] Linux toolchain - develop for Linux desktop ā€¢ Ubuntu clang version 12.0.0-1ubuntu1 ā€¢ cmake version 3.18.4 ā€¢ ninja version 1.8.2 ā€¢ pkg-config version 0.29.2 [āœ“] Android Studio (version 4.2) ā€¢ Android Studio at /home/taha/Code/android-studio ā€¢ Flutter plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/9212-flutter ā€¢ Dart plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/6351-dart ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821) [āœ“] VS Code (version 1.56.2) ā€¢ VS Code at /usr/share/code ā€¢ Flutter extension can be installed from: šŸ”Ø https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [āœ“] Connected device (3 available) ā€¢ Redmi K20 Pro (mobile) ā€¢ def0ad20 ā€¢ android-arm64 ā€¢ Android 10 (API 29) ā€¢ Linux (desktop) ā€¢ linux ā€¢ linux-x64 ā€¢ Pop!_OS 21.04 5.11.0-7614-generic ā€¢ Chrome (web) ā€¢ chrome ā€¢ web-javascript ā€¢ Google Chrome 91.0.4472.114 ā€¢ No issues found! ```
chinmaygarde commented 3 years ago

cc @blasten for thoughts on a better workflow for local engine builds. We have a workaround right now so it should not be a blocker.

blasten commented 3 years ago

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/gradle/flutter.gradle#L371-L374 seems to be failing in this case.

@mraleph this is a bug in the Flutter plugin.

fzyzcjy commented 1 year ago

I am having the same issue, and can confirm this workaround https://github.com/flutter/gallery/issues/899#issuecomment-1427994205 solves my problem

Btw, in case anyone finds the error "Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.", please put that code at the beginning of subprojects section, not the end.

parlough commented 9 months ago

In light of https://github.com/flutter/gallery/issues/1072, I'm going to close this in favor of https://github.com/flutter/flutter/issues/104667. Thanks everyone for helping each other debug and work around this!