Minimum Necessary files for an android build

强颜欢笑 提交于 2021-02-08 11:15:27

问题


Trying to find the bare minimum source and build files needed to build an android project in Android Studio. I want to publish to github and avoid uploading generated build files or binaries.

I do have a Android.gitignore from but I still see some more files getting pushed into the repo which may not be necessary. I understand the few obvious ones but about others, do I need them and if so kindly explain the usage.

So the question, do I need the following and if so then a short description of why?

root

  1. build.gradle

  2. gradle.properties

  3. gradlew

  4. gradlew.bat

  5. settings.gradle

/app

  1. app/build.gradle

  2. app/proguard-rules.pro

/gradle (tested, android can re-download/generate following it if not present)

  1. gradle/wrapper/gradle-wrapper.jar

  2. gradle/wrapper/gradle-wrapper.properties


回答1:


This question can have two different answers based on the meaning of the word needed.

First (the real one)

Assuming your project has currently those files, if your question is:

Should I commit these files on my Git repo?

The answer is yes, all of them, and I'm explaining why:

  • root

    • build.gradle -> defines the configuration for all the Gradle modules in your project (e.g. use the same remote repositories to download some Gradle plugins)
    • gradle.properties -> defines some optional flags used when building the app (e.g. enabling the incremental KAPT, enabling the AndroidX jetifier)
    • gradlew -> invokes the Gradle wrapper (which can be found under gradle/wrapper/gradle-wrapper.jar) to avoid to have Gradle installed when building your project on Darwin/Linux
    • gradlew.bat -> the same of gradlew but for Windows
    • settings.gradle -> defines the list of modules which are part of your project
  • app/

    • app/build.gradle -> defines the configuration only for your app module (e.g. its build types, its flavors, its version code and version name)
    • app/proguard-rules.pro -> defines the obfuscation rules when your app enables the minification
  • gradle/

    • gradle/wrapper/gradle-wrapper.jar -> provides the same version of the Gradle wrapper jar for all the users. This is very important because it forces the users to use the same version of the Gradle wrapper to compile your app
    • gradle/wrapper/gradle-wrapper.properties -> same as above, it defines which version of the Gradle wrapper you need

Second (the useless one)

Now, I'll give you the answer to the question:

Are these files strictly needed to compile an Android project?

To successfully compile an Android project with Gradle you just need the root build.gradle if you have Gradle installed on your machine or build.gradle + the wrapper files if you have not Gradle installed on your machine. Theoretically you can:

  • put your application code in the root project and that avoids you one build.gradle and settings.gradle
  • disable the obfuscation and that avoids you proguard-rules.pro
  • remove gradle.properties and set the properties via command line

Obviously this solution won't happen on a real project scenario.



来源:https://stackoverflow.com/questions/58595586/minimum-necessary-files-for-an-android-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!