Android Studio how to run gradle sync manually?

2019-01-17 19:33发布

问题:

I'm debugging Gradle issues in Android Studio and see references to "Run gradle sync", but I'm not sure how to run this command.

How do I run "Gradle sync" from Android studio or Mac terminal?

回答1:

Android studio should have this button in the toolbar marked "Sync project with Gradle Files"

OR by going to Tools -> Android -> Sync Project with Gradle Files from the menubar.

EDIT: I don't know when it was changed but it now looks like this:



回答2:

Keyboard shortcut lovers can add a shortcut for running gradle sync manually by going to File -> Settings -> Keymap -> Plugins -> Android Support -> Sync Project with gradle files (Right click on it to add keyboard shortcut) -> Apply -> OK and you are done. Choose any convenient key as your gradle sync shortcut which doesnot conflict with any other shortcut key, (I have choosen Shift + 5 as my gradle sync key), so next when you want to run gradle sync manually just press this keyboard shortcut key.



回答3:

With command line in your root project

./gradlew build

It will sync and build your app

To see all available gradle task, use ./gradlew tasks



回答4:

In Android Studio 3.3 it is here:

According to the answer https://stackoverflow.com/a/49576954/2914140 in Android Studio 3.1 it is here:

This command is moved to File > Sync Project with Gradle Files.



回答5:

I presume it is referring to Tools > Android > "Sync Project with Gradle Files" from the Android Studio main menu.



回答6:

gradle --recompile-scripts

seems to do a sync without building anything. you can enable automatic building by

gradle --recompile-scripts --continuous

Please refer the docs for more info:

https://docs.gradle.org/current/userguide/gradle_command_line.html



回答7:

Shortcut (Ubuntu, Windows):

Ctrl + F5

Will sync the project with Gradle files.