`.gitignore` for an Ionic project with Android target
Asked Answered
A

3

20

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?

Annmarie answered 25/7, 2020 at 5:44 Comment(2)
you should include all of those folders, i would not add them .gitignoreLachrymator
Are you saying they are not build components that can be regenerated? What is the reasoning?Annmarie
K
16

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.

Kistner answered 16/8, 2020 at 17:2 Comment(2)
I understand that I should commit the /android folder since "Capacitor native projects (android, ios, etc) are source assets (not build assets like with Cordova) so they should be committed." (source). This makes sense. But if I build an APK from Android Studio, /android/app/build/outputs/apk-debug.apk is created which clearly is a build artifact and thus shouldn't be committed. So I guess I should ignore this? Are there more build artifacts like this that I should ignore?Beverly
If found this example for .gitignore with Android Studio, which adds /*/build/ to .gitignore and I found another example that ignores .apk and similar files. I went with the first...Beverly
U
18

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)
Unhurried answered 17/8, 2020 at 17:20 Comment(1)
i have third party sdk SdkName.arr file added in android/app/lib folder. but when i am committing it to github it not uploading to git repo. how can i add this lib folder to my githubQuadrireme
K
16

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.

Kistner answered 16/8, 2020 at 17:2 Comment(2)
I understand that I should commit the /android folder since "Capacitor native projects (android, ios, etc) are source assets (not build assets like with Cordova) so they should be committed." (source). This makes sense. But if I build an APK from Android Studio, /android/app/build/outputs/apk-debug.apk is created which clearly is a build artifact and thus shouldn't be committed. So I guess I should ignore this? Are there more build artifacts like this that I should ignore?Beverly
If found this example for .gitignore with Android Studio, which adds /*/build/ to .gitignore and I found another example that ignores .apk and similar files. I went with the first...Beverly
F
3

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

Footsore answered 27/5, 2021 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.