问题
Does anyone have or know of a detailed answer to how these three functions in android studio work (I think Eclipse, and probably IntelliJ also, have the same or similar functions). I have seen and been told answers that give a brief outline of how they work and from what I understand a rebuild will also clean the project and running the project runs the last built version of the available code. Ultimately, I am just looking for an in depth explanation of how these three functions work with/inside of each other and whether it is necessary to run one before the other before running the latest app version.
回答1:
Using gradle and more specifically the gradle wrapper you can see exactly what each of these is doing by adding an info tag when running from the root of your project.
Will show you the main tasks runnable from root project ./gradlew tasks
Will show you all tasks available in your project ./gradlew tasks --all
you can find out more about any tasks by using
./gradlew help --task <task>
Android tasks
androidDependencies
- Displays the Android dependencies of the project.
signingReport
- Displays the signing info for each variant.
sourceSets
- Prints out all the source sets defined in this project.
Build tasks
assemble
- Assembles all variants of all applications and secondary packages.
assembleAndroidTest
- Assembles all the Test applications.
assembleDebug
- Assembles all Debug builds.
assembleDevelopment
- Assembles all Development builds.
assembleRelease
- Assembles all Release builds.
build
- Assembles and tests this project.
buildDependents
- Assembles and tests this project and all projects that depend on it.
buildNeeded
- Assembles and tests this project and all projects it depends on.
mockableAndroidJar
- Creates a version of android.jar that's suitable for unit tests.
Build Setup tasks
init
- Initializes a new Gradle build. [incubating]
wrapper
- Generates Gradle wrapper files. [incubating]
Verification tasks
check
- Runs all checks.
clean
- Deletes the build directory.
connectedAndroidTest
- Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck
- Runs all device checks on currently connected devices.
connectedDevelopmentDebugAndroidTest
- Installs and runs the tests for developmentDebug on connected devices.
deviceAndroidTest
- Installs and runs instrumentation tests using all Device Providers.
deviceCheck
- Runs all device checks using Device Providers and Test Servers.
lint
- Runs lint on all variants.
lintDevelopmentDebug
- Runs lint on the DevelopmentDebug build.
lintDevelopmentRelease
- Runs lint on the DevelopmentRelease build.
This is a good way to learn the ./gradlew commands available for your project
回答2:
Android Studio is based on InteliJ so you can check the information on its documentation.
Run Project
Compile . All the source files in the specified scope are compiled. The scope in this case may be a file, a package, etc.
Rebuild Project
Rebuild Project. All the source files in the project are recompiled. This may be necessary when the classpath entries have changed, for example, SDKs or libraries being used added, removed or altered.
Clean Project
It removes whatever already-compiled files are in your project
(Other explanation)
It removes the .class files and recompiles the project. Basically, it forces a rebuild.
来源:https://stackoverflow.com/questions/34345844/clean-project-vs-rebuild-project-vs-run-project-in-android-studio