Does a PhoneGap plugin have to be packaged separately? - android

I'm working on a new PhoneGap 3.* application. I'll require access to a number of native components. However, these components aren't of general usefulness; they're native libraries that we've built that the application needs to access.
In reading how to access this native code, it's obvious we need to write plugins. However, all of the docs suggest that these plugins need to be in their own git repositories. I don't see any information on building plugins without this requirement.
This is a problem for us. Most importantly, we don't use git, and that's not something that's negotiable (certainly not in the short term). Secondly, I'd sure love to have the native code reside in the same source tree as our phonegap code, since it's not going to be reused elsewhere.
Is there the option of dropping our native code inside of a phonegap project somewhere?

It's not a requirement that you use git, it's just the way it's mostly done
If you for instance make your plugin and put it in the plugins/ folder on your own to finish the installation do:
cordova plugin add plugins/com.example.test-plugin
The plugin installation is handled by plugman and is a good place to figure out more about how the plugins work.
For the case of local install it should basically turn out to adding a JSON file for your platform with a listing of the paths of plugins to install on build.

Before adding plugins to your application git command line tool is required.
You could download and install git command line for Mac OS X in here. For windows, Download Git from Here. Then: git clone git://project.url.here
Then you can add plugin and try run the command like
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
Once successfully running the command, then your project directory that particular plugin supporting java script and Native java code will be generated.

Related

`.gitignore` for an Ionic project with Android target

I'm creating an Ionic project using Capacitor (edit: the newer recommended framework compared to Cordova) and added Android as a target.
I've been able to build the app and add the Android target, which creates a bucketload of files under android/, using:
ionic build
ionic cap add android
Then, I was able to launch Android Studio and emulate my app, using npx cap open android, with "Run App" in Android Studio. This added a few more bucketloads of files.
I was able to get most of them to be ignored by adding the "ionic" and "AndroidStudio" gitignore entries from gitignore.io, but if someone clones the repo, they can rebuild the entire Android directory from scratch, right? Do I just consider everything in the android folder to be a build artifact that can be recreated from the core ionic project using capacitor (i.e. "cap").
Is there anything that needs to be saved to the repo in the ionic android directory? If so, which files - or should I fall back to ionic/Android Studio gitignore entries for the android folder?
Is there anything that needs to be saved to the repo in the ionic android directory?
I would suggest that you include your native folders in your repo as well.
Based on my experience with capacitor over the past year while developing two applications, consider these things.
Most of the times you will be using at least a few cordova plugins, since capacitor still doesn't have a viable plugin for certain features.
These plugins, will require you to manually add some variables ( like sdk keys ) or initialization function on the native side of the codes.
In fact, even for capacitor community plugins ( which are plugins created by other samaritans ), you will have to add some minimum lines of code to the native side. Consider this plugin for facebook sign in. Just go through the installation steps, you will see a long list of configurations on both ios and android sides.
Capacitor is not formerly Cordova. Both of these are different frameworks. Capacitor completely depends on native ide's for compilation, whereas cordova cli could build the native codes for you (ios, mac required).
but if someone clones the repo, they can rebuild the entire Android directory from scratch, right?
When your application grows, depending on its intended functionality, this would not be an easy task. They will have to go through all these minor tweaks to get it working.
All in all, put your native code in the repo as well. For me, the repository size with the native codes is not terribly huge.
In Capacitor you are supposed to commit the ios and android folders. They contain their own .gitignore files with the recommended files for iOS and Android.
They are not build artifacts, if you change icons or configurations (in Info.plist, AndroidManifest.xml, etc) and you delete the folders, those changes will be lost.
If you clone a Capacitor project you should run this commands:
npm install (or other install package depending on your package manager)
npm run build (or ionic build if using ionic)
npx cap sync (this copies files and generates non committed files)
As #jcesarmobile
In Capacitor you are supposed to commit the ios and android folders. They contain their own .gitignore files with the recommended files for iOS and Android.
But if you're looking for a .gitignore to use at the root of your project, this one should do the job.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.vscode
.idea
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional eslint cache
.eslintcache

How can I cleanly automate Cordova plugin management in non-Cordova based android application?

Preface
I have an android app that was already prebuilt but I later decided I wanted to add Cordova functionality by embedding it in the webviews. I was able to accomplish this by following the instructions
here on the Cordova official documentation (made the jar, applied it to my view, ect)
This works fine and dandy if I simply download the plugins and manage them manually I.E. manually move the java and js files over to my project following the proper project structure AND manually editing the config.xml and cordova_plugins.js files.
The Problem
I want to take all the manual work out of the equation when adding a new plugin. I am looking for a way to have the simplicity of "cordova plugin install" but I cannot utilize this tool because my project "is not a Cordova project." I did not set it up using Cordova but instead just added the lib jar to my project.
What I have tried
Cordova package management tools - Not a option. "Not a Cordova project"
NPM - Pulls everything but also doesn't handle the configuration changes.
Plugman - Works! BUT it is installing the whole plugin library into my project including all the other platforms (blackberry, ios, ect) code that I do not want. I understand that these libs also contain config information for the plugins, but this does simply causes my app size to be huge and adds a bunch of unneeded files.
Example of plugman command:
plugman install --platform android --project project/path/ofManifest --plugin cordova-plugin-camera
As you can see I do provide the platform and it does plug into the app properly but the original plugin library all sticks around as well.
For all of the above I actually setup a package json and have npm fire off post install js scripts. When finished it will then go use npm/cordova/plugman to install the plugins I need.
Note - I have not tried ionic because I cannot get past the firewall with the download
The question
Is there a way to just install the android-only version of a plugin including the auto configuration modifications that the other tools already do without adding a bunch of other noise the the plugin provides? I have looked around google and stack and plugman is the general answer but as state in my write up, it is including other platform lib code that I do not want in my apk.

How to install JXcore with Visual Studio and Cordova

I am working on a small project, and I am new to Cordova. I am reusing some old scripts I made for use with Node.JS but Cordova is missing many of the functions they require. I read about is and learned JXcore may be the solution to this problem, however I cannot comprehend the installation directions. I was hoping someone could dumb it down for me. I plan on releasing this application on Windows and Android, if that is important.
Please check the instructions on jxcore-cordova repository. It has been just updated for Visual Studio installation.
https://github.com/jxcore/jxcore-cordova#visual-studio
Yes, you can use your nodejs libraries in phone using JXcore cordova plugin. It's easy to create sample JXcore cordova project this way:
Download and install JXcore (For windows)
Run install_and_run.bat. You can find it here.
This bash script automates installation process. First it creates sample cordova project, then downloads and adds JXcore cordova plugin, adds platforms to project and finally runs app.

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.

why $cordova prepare when use a new phonegap-cordova api(plugin)

Im new with phonegap, cordova and android. Im on mac, recently i install all the needs:
Phonegap 3.3.0-0.19.6
Cordova 3.3.1-0.4.1
Got Android SDK and running on eclipse with no problem. Then create a new Android application on eclipse for phonegap successfully, and running on a phone with android.
Then i create another app with cordoba(terminal), put 2 platforms android and ios, i run prepare etc.. and then import the project(android) into eclipse. At this point the app runs ok, so i proceed to install some plugins for testing (Notifications and Device)
https://cordova.apache.org/docs/en/3.0.0/cordova_device_device.md.html#Device
When i run the app with eclipse the examples always return
Uncaught TypeError: Cannot call method 'alert' of undefined
And its the same with device. So looking over the internet i found that if i run $cordova prepare will work, then i run the command, then run the app on eclipse and it work but always when i install a new plugin for testing i have to run cordova prepare, and the problem is that index.html rewrite with example hello world and i loose my code.
Any help over here, im doing ok?, how to install those plugins and make the test and dont have to run prepare all the time. (Please think on eclipse, i dont what to use terminal all the time)
I had the same exact problem and other posts suggestions didn't work for me.
I solved it by switching the steps a bit, despite the official docs and other posts.
If I add ALL the files AND the core plugins BEFORE I add the platforms, then adding the platforms takes these things with it into the new folder structures AND only build once from the command line before I open the project.
If I need to add anything I do it again. Although I can edit the www files without going through the process again, I do not expect the root www to perpetuate the platform www's. I just copy it myself into all the www folders. It shouldn't be this way but I think this is a well documented bug with multiple command line builds, for now and thats my working fix.
The recommended way is to edit html/js/css... in the root www folder of the project, not in the platfotms/xxx folders.
The reason is that if you have multiple platforms, you just need to modify in one place and cordova prepare or cordova build or phonegap build will propagate your code to all the platforms and update plugins.
If you have only android platform and want to be able to change code directly in eclipse for the platforms/android/assets/www folder, I suggest you create a shell script to
copy all the content of projectroot/platforms/android/assets/www to projectroot/www
run cordova prepare android
Then, instead of running cordova prepare android, you'll just have to run your script after you add new plugins.
Edit
I think there may be a better way for your problem.
You should be able to use plugman to install your plugins instead of cordova.
First you need to install plugman cli : npm install -g plugman
then install a plugin using
plugman -d --platform android --project projectname --plugin nameorurlofplugin
http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html
I had these issues too.
One approach I use now is:
Edit the index.html in the platform folders which is platform/iOS/appname/www and so. Then add plugins using the normal terminal way using cordova plugin add but always run the project using Xcode for iOS and eclipse and not from the terminal because then you will lose your code.
From my experience when you run using .xcodeproj or say android project the www on the inside is used and if you use cordova run ios from terminal the www on the outside will overwrite the www in the platform folders.
If you get xcode errors saying can't find so and so plugin files just move them to the path the error says xcode expects them to be in.

Categories

Resources