Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crate directory is missing a Cargo.toml file; is native the wrong directory? #10

Closed
prashantjdgit opened this issue May 4, 2023 · 20 comments

Comments

@prashantjdgit
Copy link

No description provided.

@prashantjdgit
Copy link
Author

We are using this patch in flutter web app.
After installing the rust successfully ,we have to hit this command - ./build_tools/build_web.sh
but we are getting the error - Error: crate directory is missing a Cargo.toml file; is native the wrong directory?
Caused by: crate directory is missing a Cargo.toml file; is native the wrong directory?

Please guide.

@harryfei
Copy link
Member

harryfei commented May 4, 2023

If you just use the flutter patch, you can skip building the rust stuff.
This project use rust just for some wasm api.

Besides, I don't know why you get the Cargo.toml error in your environment. What build_web.sh does is just using wasm-pack to build rust to wasm. It's a simple command, you can debug it.

@prashantjdgit
Copy link
Author

Understood. We just want to build a flutter web app and apply the patch for performance improvements. Should we just run the patch script after flutter build web command?

@harryfei
Copy link
Member

harryfei commented May 4, 2023

Yeah, you are right.

@prashantjdgit
Copy link
Author

I am getting this error

./build_tools/patch_web.sh
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

@prashantjdgit
Copy link
Author

I downloaded your code and copied build_tools and native folder into root of my flutter project, Did I missed something?

@harryfei
Copy link
Member

harryfei commented May 4, 2023

Maybe flutter version, this patch needs flutter master channel.

You can view the patch files in build_tools and add changes to your generated flutter.js and flutter_servicewoker.js. It's easy to do it by manual.

@prashantjdgit
Copy link
Author

I'm already on master channel btw

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.10.0-7.0.pre.16, on Ubuntu 22.04.2 LTS 5.19.0-41-generic, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.3)
[✓] VS Code
[✓] Connected device (2 available)
[✓] Network resources

@harryfei
Copy link
Member

harryfei commented May 4, 2023

Besides, flutter changes recently.

Replace those code in your patched flutter.js.

++      const isMobile = /Mobi/i.test(window.navigator.userAgent);
++      const isChromium = window.navigator.userAgent
++                               .toLowerCase()
++                               .indexOf('chrome') > -1;
++
++      if (!isMobile) {
++        if (isChromium) {
++          fetch("canvaskit/chromium/canvaskit.js");
++          fetch("canvaskit/chromium/canvaskit.wasm");
++        } else {
++          fetch("canvaskit/canvaskit.js");
++          fetch("canvaskit/canvaskit.wasm");
++        }
++      }

@prashantjdgit
Copy link
Author

I was able to run it but at one place got error

.```
/build_tools/patch_web.sh
patching file build/web/flutter.js
patch unexpectedly ends in middle of line
patching file build/web/flutter_service_worker.js
Hunk #1 succeeded at 90 with fuzz 1 (offset 61 lines).
Hunk #2 succeeded at 150 (offset 61 lines).
patch unexpectedly ends in middle of line
Hunk #3 succeeded at 180 with fuzz 1 (offset 61 lines).

@prashantjdgit
Copy link
Author

Can you send us the new patch files?

@harryfei
Copy link
Member

harryfei commented May 4, 2023

Sorry, it's not ready to share. You can check your patch result to verify it's patched correct or not.

It's know that flutter master channel changed flutter.js flutter_servicework.js frequently.

@prashantjdgit
Copy link
Author

prashantjdgit commented May 4, 2023

should I downgrade to specific master commit where I can apply your patch? Also when will you be able to share new patch?

@prashantjdgit
Copy link
Author

Besides, flutter changes recently.

Replace those code in your patched flutter.js.

++      const isMobile = /Mobi/i.test(window.navigator.userAgent);
++      const isChromium = window.navigator.userAgent
++                               .toLowerCase()
++                               .indexOf('chrome') > -1;
++
++      if (!isMobile) {
++        if (isChromium) {
++          fetch("canvaskit/chromium/canvaskit.js");
++          fetch("canvaskit/chromium/canvaskit.wasm");
++        } else {
++          fetch("canvaskit/canvaskit.js");
++          fetch("canvaskit/canvaskit.wasm");
++        }
++      }

Do I need to update your patch file with this code?

@harryfei
Copy link
Member

harryfei commented May 4, 2023

should I downgrade to specific master commit where I can apply your patch? Also when will you be able to share new patch?

try to downgrade flutter to a commit at March 1. I think they don't change at that time.

@prashantjdgit
Copy link
Author

I have tried to update flutter.js.patch but getting below error

patching file build/web/flutter.js
patch: **** malformed patch at line 21: +        } 
--- build/web/flutter.js.orig	2023-03-01 15:40:58.588065610 +0800
+++ build/web/flutter.js	2023-03-01 15:43:48.879605009 +0800
@@ -375,7 +375,16 @@
       // Install the `didCreateEngineInitializer` listener where Flutter web expects it to be.
       this.didCreateEngineInitializer =
         entrypointLoader.didCreateEngineInitializer.bind(entrypointLoader);
-      return entrypointLoader.loadEntrypoint(entrypoint);
+      const main = entrypointLoader.loadEntrypoint(entrypoint);
+      const isMobile = /Mobi/i.test(window.navigator.userAgent);
+      const isChromium = window.navigator.userAgent
+                               .toLowerCase()
+                               .indexOf('chrome') > -1;
+
+      if (!isMobile) {
+        if (isChromium) {
+          fetch("canvaskit/chromium/canvaskit.js");
+          fetch("canvaskit/chromium/canvaskit.wasm");
+        } else {
+          fetch("canvaskit/canvaskit.js");
+          fetch("canvaskit/canvaskit.wasm");
+        }
+      }
+      fetch("assets/FontManifest.json");
+      fetch("assets/fonts/MaterialIcons-Regular.otf");
+      fetch("assets/packages/cupertino_icons/assets/CupertinoIcons.ttf");
+      fetch("/");
+
+      return main;
     }
   }
 

@prashantjdgit
Copy link
Author

I found this flutter commit release tag - https://github.com/flutter/flutter/releases/tag/3.7.6 .
What is proper way to downgrade flutter to this?
I went into installed flutter SDK folder and checked out this tag by using git checkout 3.7.6
But after this flutter doctor shows channel unknown instead of master. Is this correct?

@harryfei
Copy link
Member

harryfei commented May 4, 2023

I have no experience about downgrading the flutter.

@harryfei
Copy link
Member

harryfei commented Sep 6, 2023

@prashantjdgit I add the new patch in master branch. The patch don't need flutter nightly anymore.

@harryfei harryfei closed this as completed Sep 6, 2023
@Sucio505
Copy link

Theodore Manzanares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants