76

What is a legit .gitignore for a Flutter project that is developed in Android Studio?

This is what I have so far, but when I open up the project in Android Studio I am unable to enable Dart Support or browse the project.

#flutter specific
.flutter-plugins
.DS_Store
.dart_tool/
.packages
.pub/
build/
android/app/google-services.json
.idea/
android/key.properties
pubspec.lock
doc/api/

#ios specific
ios/.generated/
ios/Podfile*
ios/Flutter/Debug.xcconfig
ios/Flutter/Release.xcconfig
ios/Runner.xcworkspace/contents.xcworkspacedata

#android specific
android/app/google-services.json
android/key.properties

# User-specific
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml

# File-based project format
*.iws

# IntelliJ
out/
dazza5000
  • 7,075
  • 9
  • 44
  • 89
  • 12
    Have you tried gitignore.io? There are usually some pretty sane defaults there: https://www.gitignore.io/api/android,flutter,androidstudio – tylerargo Sep 12 '18 at 01:53
  • 3
    When you create a new Flutter project a `.gitignore` file is created already. What's wrong with that file? This file is not related to "enable Dart support". – Günter Zöchbauer Sep 12 '18 at 02:49
  • Your problem with "enabling Dart support" is because of the .idea in your .gitignore. .idea has codeStyle that makes Android Studio recognize your project as a dart project. Also check [this link](https://github.com/flutter/flutter/issues/13892) about making a .gitignore for flutter projects. – Serl Sep 13 '18 at 20:53
  • 2
    Shall the `*.g.dart` be ignored? – ch271828n Feb 15 '20 at 12:19

6 Answers6

77

This is the .gitignore generated automatically by Android Studio, hope that this is what you're looking for:

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
/build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
SugaR256
  • 963
  • 10
  • 9
  • 3
    Shall the `*.g.dart` be ignored? – ch271828n Feb 15 '20 at 12:19
  • 5
    Shouldn't pubspec.lock also be ignored? – DroidDev Apr 12 '20 at 03:59
  • 3
    It should be commited for applications: "For application packages, do commit pubspec.lock. This file is the recommended way for non-shared resources such as applications to manage their dependencies." https://dart.dev/guides/libraries/private-files – nstrelow May 05 '20 at 18:21
  • For library packages, don’t commit the pubspec.lock file. Regenerating the pubspec.lock file lets you test your package against the latest compatible versions of its dependencies. See https://dart.dev/guides/libraries/private-files#pubspeclock for more info. – Zeeshan Ansari Nov 18 '21 at 06:44
  • gradlew seems to need to be checked in version control, instead of gitignored. see: https://stackoverflow.com/questions/43954932/should-i-gitignore-my-gradlew – ch271828n Aug 18 '22 at 01:46
15

You can find it in official project of flutter on Github here:

# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.classpath
.project
.settings/
.vscode/

# Flutter repo-specific
/bin/cache/
/bin/internal/bootstrap.bat
/bin/internal/bootstrap.sh
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/devicelab/ABresults*.json
/dev/docs/doc/
/dev/docs/flutter.docs.zip
/dev/docs/lib/
/dev/docs/pubspec.yaml
/dev/integration_tests/**/xcuserdata
/dev/integration_tests/**/Pods
/packages/flutter/coverage/
version
analysis_benchmark.json

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
**/generated_plugin_registrant.dart
.packages
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
*.jks

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/ephemeral
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# macOS
**/macos/Flutter/GeneratedPluginRegistrant.swift

# Coverage
coverage/

# Symbols
app.*.symbols

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock

Here just some points to note when making changes on .gitgnore file to ensure Git is always tracking the right files.

  1. Make changes in .gitignore file.
  2. Run git rm -r --cached . command.
  3. Run git add . command
AnasSafi
  • 5,353
  • 1
  • 35
  • 38
  • I think that this is not meant to be included in Flutter projects. Just think that all .lock files are ignored... – vincendep Nov 23 '22 at 13:01
9

VSCode provides this and is equally good as the android studio version

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

Trect
  • 2,759
  • 2
  • 30
  • 35
7

Here is Consistent .gitignore for Dart and Flutter projects all Editors

  • Android Studio
  • VisualStudioCode
  • Xcode

https://github.com/flutter/flutter/issues/13892#issue-285842688

Nikunj Kumbhani
  • 3,758
  • 2
  • 26
  • 51
1

Here is a legit .gitignore for Flutter 2.2 taken from Very Good Core cli

# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/*

# Visual Studio Code related
.classpath
.project
.settings/
.vscode/*

# Flutter repo-specific
/bin/cache/
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/docs/doc/
/dev/docs/flutter.docs.zip
/dev/docs/lib/
/dev/docs/pubspec.yaml
/dev/integration_tests/**/xcuserdata
/dev/integration_tests/**/Pods
/packages/flutter/coverage/
version

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds
.fvm/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
**/android/.idea/
*.jks

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/.last_build_id
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Coverage
coverage/

# Submodules
!pubspec.lock
packages/**/pubspec.lock

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Exceptions to the above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock
!.vscode/launch.json
!.idea/codeStyles/
!.idea/dictionaries/
!.idea/runConfigurations/
Adam Smaka
  • 5,977
  • 3
  • 50
  • 55
0

.gitignore below excludes all files and folders except: lib/, pubspec.yaml and AndroidManifest.xml i.e. only manually changed files:

.dart_tool
.flutter-plugins
.flutter-plugins-dependencies
.gitignore
.idea
.metadata
.vscode

build
assets

#ignore android except android/app/src/main/AndroidManifest.xml
android/*
!android/app
android/app/*
!android/app/src
android/app/src/*
!android/app/src/main
android/app/src/main/*
!android/app/src/main/AndroidManifest.xml


ios
linux
macos
web
windows
README.md
pubspec.lock

Only for local use. If you publish to Github or another shared repository use the default file.

Yuriy N.
  • 4,936
  • 2
  • 38
  • 31