Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`.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?

like image 961
LightCC Avatar asked Jul 25 '20 05:07

LightCC


3 Answers

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.

like image 127
Chetan Bansal Avatar answered Oct 17 '22 17:10

Chetan Bansal


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)
like image 42
jcesarmobile Avatar answered Oct 17 '22 18:10

jcesarmobile


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

like image 3
crg Avatar answered Oct 17 '22 18:10

crg