In my flutter project when I run either :
./gradlew build
or
gradle build
I get this type of error :
.dart_tool/flutter_build/generated_main.dart:11:8: Error: Error when reading 'lib/main.dart': Le fichier sp├®cifi├® est introuvable.
This is because my main.dart is located in "lib/src/main" instead of "lib" , and it needs to stays that way.
When I run my build with flutter I use an option to specify the main location :
flutter build apk -t "lib/src/main/main.dart"
And it works fine.
Is there such option for./gradlew build or gradle build ?
Thanks.
Here's the answer...
./gradlew build -Ptarget=lib/entry_point_name.dart
The -P indicates gradle that what follows is a project parameter, in this case the parameter's name is 'target'. This parameter is used to override the default main.dart entry point.
If you are using android studio then follow these steps:
1: Go to edit configurations
2: Change the entry point
Thats it.
I'm trying to run an existing React Native project that uses Metro Bundler. My operating system is Ubuntu 20.04 and I've tried to run the app both on a physical Android device and on an Android simulator that I created with Android Studio.
I have successfully cloned the project's repo, installed its dependencies (yarn), built the app (react-native run-android), and opened the app on my phone and simulator. However, running react-native start errors out saying TypeError: cb.apply is not a function. Here is the full information and errors I get when running react-native start:
$ react-native start
warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn The following packages use deprecated "rnpm" config that will stop working from next release:
- rn-fetch-blob: https://npmjs.com/package/rn-fetch-blob
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ Running Metro Bundler on port 8081. │
│ │
│ Keep Metro running while developing on any JS projects. Feel free to │
│ close this tab and run your own Metro instance if you prefer. │
│ │
│ https://github.com/facebook/react-native │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn The following packages use deprecated "rnpm" config that will stop working from next release:
- rn-fetch-blob: https://npmjs.com/package/rn-fetch-blob
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
Looking for JS files in
/home/ggiuffre/Documents/squib/app
Loading dependency graph, done.
BUNDLE [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1)/home/ggiuffre/Documents/squib/app/node_modules/#react-native-community/cli/node_modules/graceful-fs/polyfills.js:285
if (cb) cb.apply(this, arguments)
^
TypeError: cb.apply is not a function
at /home/ggiuffre/Documents/squib/app/node_modules/#react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20
at FSReqCallback.oncomplete (fs.js:169:5)
Installing graceful-fs (as recommended by another post about the same problem) doesn't change anything, and I still get the same error.
What could be the issue here?
I had a very similar problem on CI, but it works normally on my local machine (Node 13). In the CI, when building the project on CircleCI or on AppCenter with a code that I already released two months ago it throws the error below. It just does not make sense, it's like node had broken dynamically.
I tested the same code with node 10, 12 and 14, but now it works just with node 10 (10.22.0).
The error I had:
/home/circleci/my-app/node_modules/#react-native-community/cli/node_modules/graceful-fs/polyfills.js:285
if (cb) cb.apply(this, arguments)
^
TypeError: cb.apply is not a function
at /home/circleci/my-app/node_modules/#react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20
at FSReqCallback.oncomplete (fs.js:169:5)
> Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1
UPDATE
What solved my problem was to add a resolution to the package.json to do not allow any lib to use a version of graceful-fs that is before "4.2.4". Now it works again with node 12.
PS: Don't forget to run yarn or npm run install to update your .lock. If this solution does not work for you, please add a comment to this thread related to this problem on Node 12.18.3
"devDependencies": {
...
},
"resolutions": {
"graceful-fs": "4.2.4"
},
I got this too today when doing a build. (running node 12.8.3)
I reinstalled the follow package:
npm install graceful-fs --save-dev
This solved the above problem.
An Ubuntu 20.04 user here with node 16.0.0. I was getting the same error when I would run:
> npx create-react-app [my app]
I found that I had to reinstall create-react-app (remove it from node_modules first) to solve it.
> npm install create-react-app
I solved it on both my computers. One needed more work on it.
Option 1:
Follow this directory C:\Users(your username)\AppData\Roaming
Delete the npm folder
and if there is one npm cache folder. Run npm clean cache -force, or npm cache clean -force on windows ( — force is now required to clean cache)
You should be good now if not do option 2.
Option 2:
Follow this directory C:\Users(your username)\AppData\Roaming
Delete the npm folder
and if there is one npm cache folder. Run npm clean cache -force on linux, or npm cache clean on windows ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted
and uninstalled NodeJS.
Reinstall Nodejs.
You should be good now.
If you have nvm installed, its even simpler. To check this, run
nvm --version
then to install the latest lts version of node, run
nvm install --lts
That's what worked for me, let me know if that helps
If you are using Windows 10, I solved this issue by doing the followings:
First, this was the error:
Navigate to %USERPROFILE%\AppData\Roaming\
Remove any cache that may be there by typing Run npm clean cache —force
Remove the NPM Folder
Re-install the Node.js and make sure to include NPM during the installation of Node.js
After the above steps, I am able to run the npm like before and add modules that I needed.
On Windows:
Goto the path
C:/Users/{User}/AppData/Roaming
delete the 2 folders
npm
npm-cache
at path
npm clean cache —force
In my case I was trying to use Husky and this error occurs:
husky > commit-msg (node v15.6.0)
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! ~/.npm/_logs/2021-01-24T06_04_04_218Z-debug.log
>>> Installation [ 'commitlint#latest' ] fail with code 1 <<<
husky > commit-msg hook failed (add --no-verify to bypass)
I run the command below and problem was solved
npm i -D commitlint
Your node version is not matching with the libraries/frameworks you are trying to use.
Try to update you node version and check.
Better to use nodist/nvm to do upgrade or downgrade with finger snap.
The problem is occuring because of new npm naming restrictions. Project names can no longer contain capital letters. Rename the directory with lower case letters.
if (cb) cb.apply(this, arguments)
^
TypeError: cb.apply is not a function
at /home/circleci/my-app/node_modules/#react-native-community/cli/node_modules/graceful-fs/polyfills.js:285:20
For this in pollyfills.js file go to line 62,63,64 and comment those shown below, Worked for me for my Gitbook
// fs.stat = statFix(fs.stat)
// fs.fstat = statFix(fs.fstat)
// fs.lstat = statFix(fs.lstat)
I am trying to install the mqtt module to android_armv7. To do this, I create a folder named build and run this: ~/Qt/5.12.4/android_armv7/bin/qmake qmake -r ... Unfortunately I recieve this error:
Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK.
Could not read qmake configuration file /home/stefan/Qt/5.12.4/android_armv7/mkspecs/android-clang/qmake.conf.
Error processing project file: ../qtmqtt.pro
I have tried going to tools->External->Configure->Environment->External Tools->Update Translations and wrote:
"ANDROID_NDK_ROOT=/home/stefan/Downloads/android-ndk-r19c/android-ndk-r19c
PATH="
in the Environment Change section. It didn't work. A strange thing (for me) is that I can deploy an application (without mqtt) on android_armv7. I am using Linux. What should I do now?
When bundling react-native code via gradlew assembleRelease and having the generate source maps tag added to the app build.gradle, bundling error occurs.
"error ENOENT: no such file or directory,
app\build\intermediates\assets\release\index.android.js.map"
In './android/app/build.gradle', I have the extraPackagerArgs property to generate source maps.
project.ext.react = [
entryFile: "index.js",
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/assets/release/index.android.js.map"]
]
Doesn't work
When calling cd android && gradlew assembleRelease in the root of the project folder.
This however fails because it seems as though its trying to generate the source map before the bundle file index.android.bundle is even created.
example:
first I clean my project via android studio.
\android\app\build\intermediates\assets\release will be empty.
next, run cd android && gradlew assembleRelease.
The error is displayed stating that there is no bundle file as its trying to make a sourcemap.
Works
example:
clean the project via android studio
run cd android && gradlew assembleRelease without having extraPackagerArgs in the build.gradle file.
The bundle is created in ..\intermediates\assets\release.
Next, add back the extraPackagerArgs for generate the sourcemap.
Run again cd android && gradlew assembleRelease, and the sourcemap is created.
This tells me that whatever arguments are added to extraPackagerArgs seem to be running before the bundle is actually created.
Does anyone know a way to ensure that the sourcemaps only get generated after the bundle file is made?
When building a regular Android app with Gradle, I can add params as such:
./gradlew assembleRelease -Pusername=foo -Ppassword=bar
With Flutter, this is what I'm supposed to call in order to assemble an APK:
flutter build apk
How do I pass the params to Gradle in this case?
P.S. I'm trying to use Jenkins credentials in a pipeline configuration. I do not want to expose my password, so avoiding using the arguments and putting it directly into the project is not an option.
You can pass variables via the environment, I use this method with Jenkins. The job can be configured to pass the credentials via environment variables.
In your build.gradle (where needed):
username = System.getenv('SECRET_USERNAME')
password = System.getenv('SECRET_PASSWORD')
Please notice that System.getenv(...) returns null if the variable is not defined.
In your development environment you should export the variables:
$ export SECRET_USERNAME="my secret username"
$ export SECRET_PASSWORD="my super secret password"
Please, I do not know which IDE are you using, but both IntelliJ and AndroidStudio do support declaring environment variables.
You can set project properties through environment variables like ORG_GRADLE_PROJECT_foo=bar, so that you don't have to modify the gradle scripts, for example:
export ORG_GRADLE_PROJECT_username=foo
export ORG_GRADLE_PROJECT_password=bar
flutter build apk
Docs: Project properties