ignore node_modules on cordova build - android

How can I stop cordova from trying to copy my www/node_modules folder to platforms/{android/iOS}/www the when doing a build command like this:
cordova build android
This seems like a relatively straight forward thing that everybody would want to do, but everything I have found does not seem to work.
This is particularly an issue when doing a build for android as something in my node folder is causing the build to fail.
I am hoping there is a way to leverage the config.xml file for this.

Don't include node_modules in /www. It should be one level up. My guess is that you initialized your npm project from the incorrect directory.

Have your build process that needs node_modules for Grunt and Bower run in some other folder in your project, one that is at the same level in the folder hierarchy as www perhaps. Then at the end of your build process, have the build tools copy the built artifacts into www before kicking off cordova build <platform name>.

Related

How to launch a Cordova project with full rebuilding of plugins?

I'm working on a Cordova plugin. As a plugin can't be executed, I'm using a Cordova project to test it. I found that running a Cordova project will not reimport and rebuild plugins, so currently I'm doing this:
rmdir \"./plugins/my-plugin\" /q /s
cordova platform remove android
cordova platform add android
cordova run android --device
Did I miss something or Cordova really doesn't have a command to fully rebuild everything before running the project?
Unfortunately, cordova will check your plugins folder only when adding or updating a plugin or platform. Then it will build and copy the needed plugin(s) into the designated OS in the platforms folder.
By your script I assume the source of the plugin is outside of the project folder. So the script you're using should do the work. But if I may give you a better solution would be as follows:
Create a Symlink/shortcut of the source folder for your plugin into the plugins folder, so you'll not need to remove the folder and stress the disk into copying files everytime you want to run the update.
Your "update" script should delete only the installed plugin folder at platforms/android/platform_www/plugins/my-plugin and it'll make the update far more quickier than removing and adding the platform again.

How to run gradle build manually on a flutter project

Currently, I am getting "Finished with error: Gradle task assembleDebug failed with exit code 1" while trying to build a Flutter project (flutter run). The logs do not help much. Therefore, i want to run "gradlew build" or similar manually with stacktrace option to see what is happening under the hood. What is the command for that ?
For posterity I will post my comment as an answer too and I'll elaborate it a bit.
When you create a flutter project there are two new folders created inside the main folder, one is android and one is ios.
The android folder contains the Android native code and all the android configurations, you can handle it as a native android project.
The ios folder contains the iOS native code and all the ios configurations, it also has the xcworkspace file which can be opened with Xcode like a normal ios project.
Now you can run platform specific commands in each folder, like i said, the folders contain actual native projects.
So for Android you could do:
cd android/
./gradlew clean
./gradlew build
(clean and build the project)
For iOS you could do:
cd ios/
pod repo update
pod install
(update the pod repo and install the pods)
Just a short reminder, if you want to create apk/ipa from the native folders, don't forget to run flutter build in the main folder, otherwise you might get outdated code in your apk/ipa.
Go to the folder where you have gradle installed(the place where your GRADLE_HOME variable points to).
Move inside the wrapper folder
Move inside the dists folder which is inside the wrapper folder
Delete everything that you can find inside the dists folder(cached gradle wrapper)
Run/launch your android flutter project again. It should re-download the gradle wrapper and if you don't have any connection problems your project should run correctly.
Note: I'm having the same problem because of my unstable internet connection. I'm ending up with a corrupted gradle wrapper file and the download doesn't restart.
If the download gets interrupted and fails to completely download and launch your project repeat all of the steps.

How to remove ALL cordova plugins from my VS2015 project?

I run into several nasty errors when attemping to remove the phonegap-plugin-push from my VS2015 Cordova project, and of course the app is now in a completely screwed state (unable to build, run, etc).
In Cordova CLI, we simply removed the platform and deleted the plugins dir, and re-added the platform to fix this problem, but I can't find any reference on how to do this with Visual Studio 2015. Deleting the plugins folder would probably cause my project to suddenly implode.
Any ideas on how to (manually?) erase all plugins from my project will be welcome, thanks.
Deleting the plugins directory... Hacky and overkill at best, risky at worst: once you add a plugin using the Cordova CLI, there will be traces of it in Cordova's config files, then it won't find them, everything will go haywire...
To remove all the plugins, just use the Cordova CLI. To list all the plugins, go:
cordova plugins
Then, for each plugin remove it as such:
cordova plugins rm org.myname.mypluginname
There is no way to remove all the plugins in one line, so unless you write a script, you're going to have to remove them one by one.
I suppose you knew all this already, but I wouldn't try any other way, be it from Visual Studio or anything else. What you did (removing all the plugins and the platforms, then adding them again) is the way I usually do it when things go sour on a specific platform.
I would just advise using the Cordova CLI to remove stuff (platforms or plugins), rather than deleting directories and then tinkering with Cordova's configuration files.

In phonegap On adding a new plugin if I rebuild my app it is removing the total project and creating a new one

Im trying to add a new plugin in phonegap, in order to work a new plugin we should rebuild the app. But if i rebuild the app my entire project is removed and it is creating a new one.
how can i use the plugin without rebuild or how can i rebuild app without loosing my code.
Im trying to add the splashscreen plugin.
First off all: I would recommend you to get a deeper look into Cordova. Therefore you need to read the Cordova Documentation.
The reason for just having a clear index and things like that is, that the command cordova build will copy all files from the root www folder into your platforms. That means, that you probably have worked in the www folders from your platforms.
Your folder structure is sth like this
So if you run the cordova build command it will copy all files from the www folder (2.) in your folders for your platforms (1.). If you now have not worked in the root www folder, it'll just copy the files which were created while you build the project the first time.
Normaly the Plugins you installed are available directly after you installed them - without a rebuild. So i would first recommend you to update your cordova (npm update -g cordova). After that you should create a new project and copy your files from your last project into the root www folder. A workflow for that should look like follows:
cordova create testProject com.example.com testProject
cd testProject
cordova platform add [platform you need]
cordova plugin add org.apache.cordova.splashscreen [plugins you need] - please note: Since Cordova is on V5, all Plugins are available via npm so the new command for installing plugins looks like: cordova plugin add cordova-plugin-splashscreen.
After you added all now you're copying the index and css file from your project into your new www root folder
Now you run cordova build
If you want an extra plugin now, which you have not installed when you created your project, you close all files your IDE (Xcode or Android Studio) and then move into your project with your terminal/console. There you can add a plugin now and it should be available after it is installed with cordova plugin add cordova-plugin-* without the build command!
Hope that helped you, let me know if you need further information!

Adding Cordova (Phonegap) Plugins manually to existing android projects

I'm trying to add additional Phonegap plugins (namely, the File plugin) to an existing android application that uses Phonegap.
I've tried navigating to my project directory (in my workspace) and then run the command
cordova plugin add https://theurlwhichworks.org/
It says the plugin is installing, and when I go to look in my workspace on my computer, there is a folder titled plugins, and inside, a directory called
org.apache.cordova.file
which means that the plugin (apparently) downloaded correctly, but doesn't seem to have been added to my project.
Is there any way to manually add this plugin (or others) to my android project directly? I build+run my application to an attached device from eclipse, because anytime I try to use the CLI with regard to cordova/phonegap I always seem to be doing something wrong, or the result is not at all what I expected.
Hopefully it is possible to add these plugins manually. I appreciate any suggestions
It is possible to add plugins manually, and that is how we did it in the old days before the Cordova/Phonegap CLI or PlugMan
options
A. use PlugMan directly
npm install -g plugman
check out the plugman documentation. Outside of a Cordova project, plugman is your best bet for a clean automated install
B. manually
add the .java files to the android project src/ directory
remember their path has to match their namespace
dump the plugin js file somewhere in assets/www/*
add a feature tag to platform config.xml
It has been a long time since I added a plugin manually, and the cordova plugin spec has gone through major changes multiple times since then. You may need to manually include the plugin js implementation (eg via script tags in index.html)
I would highly recommend you use PlugMan, or at least try before the manual install.
Seems you're using eclipse.
A cordova 3.x project looks like this :
/www
/plugins
/platforms
/platforms/android
/platforms/android/assets/www
...
When you run cordova plugin add https://theurlwhichworks.org/ the plugin is added only in the /plugins folder but not in your platform folder.
In your eclipse project you only see /platforms/android folder.
To actually add the plugin to the android platform, you have to build the platform :
cordova build android
or at least prepare the platform (same as build but does not try to compile):
cordova prepare android
But be aware that when you either build or prepare, the content of the platform/android/assets/www folder will be replaced with the content of the root www folder.
So if you've been modifying directly the assets/www folder in eclipse, DO NOT FORGET TO SAVE IT BEFORE YOU BUILD OR PREPARE!!!
Every time plugins start acting funny for me I usually remove and re-add the platform and everything usually sorts itself out. The commands for Android for example,
cordova platform remove android
cordova platform add android
If your plugin list has what you expect, re-adding the platform re-downloads all the plugins.

Categories

Resources