Android Studio how to run gradle sync manually?

情到浓时终转凉″ 提交于 2019-11-28 07:06:53
Cai

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

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

EDIT: This is what it looks like on 3.3.1


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

gradle --recompile-scripts

it will do a sync without building anything.


Alternatively, with command line in your root project

./gradlew build

It will sync and build your app, and take longer than just a Gradle sync

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

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.

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.

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

oc1d
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

Andrey

Shortcut (Ubuntu, Windows):

Ctrl + F5

Will sync the project with Gradle files.

I think ./gradlew tasks is same with Android studio sync. Why? I will explain it.

I meet a problem when I test jacoco coverage report. When I run ./gradlew clean :Test:testDebugUnitTest in command line directly , error appear.

Error opening zip file or JAR manifest missing : build/tmp/expandedArchives/org.jacoco.agent-0.8.2.jar_5bdiis3s7lm1rcnv0gawjjfxc/jacocoagent.jar

However, if I click android studio sync firstly , it runs OK. Because the build/../jacocoagent.jar appear naturally. I dont know why, maybe there is bug in jacoco plugin. Unit I find running .gradlew tasks makes the jar appear as well. So I can get the same result in gralde script.

Besides, gradle --recompile-scripts does not work for the problem.

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