Search code examples
androidgitionic-frameworkgitignorecapacitor

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


Solution

  • 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.