`.gitignore` for an Ionic project with Android target - android

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

Related

Embedding cordova application on Android native application

What I'm trying to do is embed a cordova application into a native android application.
It seems to me that the documentation is out of date or not clear about the steps that needs to be done.
Documentation:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html
I am at the point that I can't create the .jar file for the following reasons.
I don't have a /framework directory in my root project directory or in platforms/android
Cordova seems to be using gradle instead of ant for building the android project. I can't find a build.xml anywhere in the android project.
My Cordova version: 8.0.0
As as followup question, I expect this .jar file will also contain the plugins that the cordova project depends on, correct?

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.

In Cordova/Phonegap why we need to build the project for each platform?

I created a new cordova project (from the command line, cordova create firstProject com.examplefirstproject FirstProject), then I added the platoform that I need (cordova platform add android) and at this point I read from the Cordova documentation that I need to build the project (cordova build android).
Why we need to build the project?
I tried to emulate the project without building it and it works fine. So, I'm asking why I should run the command to build the project.
The "only difference" from a project where I run the build command is the presence of more folders in firstproject\platforms\android (here is the list of folders and files of the not builded project and here is the list of the builded project).
The build command will recompile the app. There are many situations when this is important to do. Whenever, you make a change to core functionality of the app (not the HTML, JS, CSS etc), you will need to re-build the app for these changes to become apparent. Also, you will find when your project is finished, in order to publish the app you will have to build a release version of the app.
You don't need to build the app when you are merely editing the content of your app, which is what is causing your confusion it would seem.
It's also worth noting that when you use the 'run' command to emulate the app, this will also create a fresh build of the 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.

Does a PhoneGap plugin have to be packaged separately?

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.

Categories

Resources