46

how to run gradle sync by command in linux ? I dont want "gradle build" cuz i know this would sync and build. I just want a command which does whatever button "sync project with gradle files" does in Android Studio.

Amir Ziarati
  • 14,248
  • 11
  • 47
  • 52
  • 2
    The "project" in this case refers to Android Studio-specific files, like the `.iml` file and the files in the `.idea/` directory. I suspect that those will only be updated from within Android Studio itself. – CommonsWare Sep 27 '16 at 13:15
  • why do you want the same from command line - the sync project with gradle files will also do some plugin magic you won't get from gradle itself. – kemuri Aug 28 '19 at 08:42
  • Can you elaborate what you want to accomplish with this sync operation in the terminal? What are you intending to sync with? The feature you're asking for doesn't exist as you're requesting. So let's figure out what will get you where you want. – Julian Nov 12 '19 at 20:47
  • 3
    We want a "Sync project with Gradle files" test as part of our automatic build validation because we sometimes get errors from it in Android Studio even though everything works from the command line. – ssenator Nov 27 '19 at 09:26
  • @Julian We also want to do a gradle sync in terminal, because we can't access to Android Studio in our automatic build environment, which runs on many remote machines. When the project updated, we really want to re-sync gradle in terminal, rather than delete the whole project and do it again, which will rebuild the entire project and cost lots of time. – kkpattern Mar 07 '20 at 03:27
  • @kkpattern What exactly would syncing on the command line solve for you? I don't think I fully understand yet. Is it to resolve your java dependencies? – Julian Mar 07 '20 at 20:57
  • @Julian Our project is mainly a native build one(most are C++ code). Sometimes the project updated and need to rerun the CMake but Gradle can't detect this. For example, we write our dependencies in a yml file. If a third library's version updated, we need to run CMake again. But Gradle won't know this. So we need syncing on the command line to force Gradle to do it. – kkpattern Mar 19 '20 at 06:19
  • Could you output the results of the `gradle tasks` (or however you invoke gradle from your environment) – Julian Mar 19 '20 at 06:29

3 Answers3

4

there is no task to trigger sync / config phase directly, but you can call:

./gradlew help

this will trigger config phase and report if it failed or was successful. This is best practice to detect non-lazy config with the help of scans too.

kemuri
  • 478
  • 4
  • 9
2

Before gradle 5.0 we can use

    ./gradlew --recompile-scripts

Will do a sync without building anything

Community
  • 1
  • 1
-5

You can explore al the tasks in:

./gradlew tasks

Otherwise if you want to sync and build your app (as root):

./gradlew build
byDavid360
  • 68
  • 9
  • 4
    i know both of this commands. the first one jsut shows the tasks list and the second one builds the project. there is a button in android studio named "sync project with gradle files" i just want to trigger this button with command. is there sth like : "./gradlew sync" for example, or sth like this that only syncs ? – Amir Ziarati Sep 28 '16 at 06:56
  • You can try (if you are Using Ubuntu) Ctrl + F5 . About commands? I dont know the command you are looking for... srry – byDavid360 Sep 28 '16 at 11:26
  • 1
    @AmirZiarati Hey, did u find a way to sync gradle from terminal?? – Pramod Garg Feb 18 '19 at 12:19