React Native and build.gradle

16,290

It is .gradle file in .gitignore and not the *.gradle or build,gradle.

So the answer to your questions is build.gradle is not ignored and should not have to be ignored.

The android related things included in .gitignore are:

build/
.idea
.gradle
local.properties
*.iml
android/gradle.properties

For standard, you can refer to this below two sample .gitignore file.(you can replace your .gitignore contents with the below link contents and can check.)

enter link description here https://github.com/facebook/react-native/blob/master/.gitignore https://github.com/facebook/react-native/blob/master/local-cli/templates/HelloWorld/_gitignore

Share:
16,290
Thanos
Author by

Thanos

EngD student in Model-driven Software Engineering. MSc in Software Engineering. BSc in Applied Informatics.

Updated on July 02, 2022

Comments

  • Thanos
    Thanos almost 2 years

    I am new to React Native and I work with a colleague on a new app. I created a new react native project which has generated a .gitgnore file as well. In it all the .gradle files (and thus the build.gradle file inside /android/ folder) are ignored.

    When I pushed the project to Github and my colleague pulled, he npm install to download the node_modules (which are also excluded <- I have read the rational behind this) and then he run react-native run-android. This failed. We realised that if he creates the build.gradle file inside /android/ and copy-paste the contents of my build.gradle which I have locally (as is ignored by git) everything runs smoothly.

    My main questions are: 1) Should the build.gradle file be ignored as react native does by default? 2) If yes, how are teams supposed to work on a react native project if they somehow need to get the build.gradle contents to run the project on their side? 3) What happens if my disk drive fails? I can pull everything from git but I will not have the build.gradle. Should I right it from scratch?

    The contents of the .gitignore file:

    # OSX
    #
    .DS_Store
    
    # Xcode
    #
    build/
    *.pbxuser
    !default.pbxuser
    *.mode1v3
    !default.mode1v3
    *.mode2v3
    !default.mode2v3
    *.perspectivev3
    !default.perspectivev3
    xcuserdata
    *.xccheckout
    *.moved-aside
    DerivedData
    *.hmap
    *.ipa
    *.xcuserstate
    project.xcworkspace
    
    # Android/IntelliJ
    #
    build/
    .idea
    .gradle
    local.properties
    *.iml
    
    # node.js
    #
    node_modules/
    npm-debug.log
    yarn-error.log
    
    # BUCK
    buck-out/
    \.buckd/
    *.keystore
    
    # fastlane
    #
    # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
    # screenshots whenever they are needed.
    # For more information about the recommended setup visit:
    # https://docs.fastlane.tools/best-practices/source-control/
    
    */fastlane/report.xml
    */fastlane/Preview.html
    */fastlane/screenshots
    
    # Bundle artifact
    *.jsbundle
    
  • Thanos
    Thanos over 5 years
    The react native's genarated .gitignore ignores it. Is it wrong?
  • K..
    K.. over 5 years
    I think it's wrong. It didn't do so in my apps and I have some custom code in it, which is needed by other devs to build.
  • Thanos
    Thanos over 5 years
    I am afraid that although your logic seems correct, I still somehow have the problem. Unless I explicitly ask the default gitignore not to ignore it (i.e., !android/build.gradle), it ignores it. I tried it in a fresh project. What am I missing?
  • Bhagwat K
    Bhagwat K over 5 years
    Can you add your .gitignore file content? So I can try to help you in that case.
  • Thanos
    Thanos over 5 years
    Uploaded the gitignore file.
  • Morris
    Morris over 2 years
    It's September 2021 today, and RN includes android/gradle.properties file in git. reactnative.dev/docs/signed-apk-android said to put some credentials like MYAPP_UPLOAD_KEY_PASSWORD in android/gradle.properties. Does anyone know if this practice is secure? I disagree with putting plain passwords in any git-checked file.