`.gitignore` 用于具有 Android 目标的 Ionic 项目

`.gitignore` for an Ionic project with Android target

我正在使用 Capacitor 创建一个 Ionic 项目(编辑:与 Cordova 相比更新的推荐框架) 并添加了 Android 作为目标。

我已经能够构建应用程序并添加 Android 目标,它在 android/ 下创建了一大堆文件,使用:

ionic build
ionic cap add android

然后,我能够启动 Android Studio 并使用 npx cap open android 和 Android Studio 中的“运行 App”模拟我的应用程序。这添加了更多的文件桶。

我能够通过添加来自 gitignore.io 的“ionic”和“AndroidStudio”gitignore 条目来忽略其中的大部分,但是如果有人克隆了 repo,他们可以重建从头开始整个 Android 目录,对吧?我是否只将 android 文件夹中的所有内容视为可以使用电容器(即“cap”)从核心离子项目重新创建的构建工件?

是否有任何需要保存到 ionic android 目录中的 repo 中的内容?如果是这样,哪些文件 - 或者我应该回退到 android 文件夹的 ionic/Android Studio gitignore 条目?

Is there anything that needs to be saved to the repo in the ionic android directory?

我建议您也将本机文件夹包含在您的存储库中。

根据我过去一年在开发两个应用程序时使用电容器的经验,consider 这些东西。

  • 大多数时候您至少会使用一些 cordova 插件,因为电容器仍然没有针对某些功能的可行插件。
  • 这些插件,需要你在代码的原生ide上手动添加一些变量(如sdk keys)或初始化函数。
  • 事实上,即使是电容器社区插件(由其他好心人创建的插件),您也必须在原生 side 中添加一些最少的代码行。缺点ider 此 plugin 用于 facebook 登录。只需完成安装步骤,您将在 ios 和 android s[=34 上看到一长串配置=]s.
  • Capacitor 以前不是 Cordova。这两个是不同的框架。 Capacitor 完全依赖原生 ide 进行编译,而 cordova cli 可以为您构建原生代码(需要 ios、mac)。

but if someone clones the repo, they can rebuild the entire Android directory from scratch, right?

当您的应用程序增长时,根据其预期的功能,这将不是一件容易的事。他们将不得不进行所有这些小调整才能使其正常工作。

总而言之,将您的本机代码也放入存储库中。对我来说,带有本机代码的存储库大小并不是很大。

在 Capacitor 中,您应该提交 iosandroid 文件夹。它们包含自己的 .gitignore 文件以及 iOS 和 Android.

的推荐文件

它们不是构建工件,如果您更改图标或配置(在 Info.plist、AndroidManifest.xml 等中)并删除文件夹,这些更改将会丢失。

如果您克隆一个 Capacitor 项目,您应该 运行 这个命令:

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)

作为@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.

但是,如果您正在寻找 .gitignore 在项目的根目录中使用,这个应该可以胜任。


# 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