问题
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
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle
/app
app/build.gradle
app/proguard-rules.pro
/gradle (tested, android can re-download/generate following it if not present)
gradle/wrapper/gradle-wrapper.jar
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
andsettings.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