18

enter image description herei have an android studio project with manifest file, the problem is when i sync the gradle it gives the error below

Gradle sync failed: Cannot get property 'sync' on null object

also this is the exception

    A problem occurred evaluating root project 'projectname'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:210)
at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:66)
at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:63)
at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:63)
at org.gradle.configuration.project.BuildScriptProcessor$1.run(BuildScriptProcessor.java:45)
at org.gradle.internal.Factories$1.create(Factories.java:26)
at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:212)
at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:193)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:42)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:35)
at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject$1.run(LifecycleProjectEvaluator.java:107)
at org.gradle.internal.Factories$1.create(Factories.java:26)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withProjectLock(DefaultProjectStateRegistry.java:238)
Malo
  • 1,232
  • 2
  • 17
  • 28

7 Answers7

23

I have tried to rename and remove the line with include ':app' from my settings.gradle or settings.gradle.kts file, Sync Project with Gradle files and revert the removed line and sync again. But it does not work for me.

What works for me is;

  1. delete folders [build, .idea, .gradle]
  2. resync or Invalidate Caches / Restart
  3. and do the same steps by removing include ':app', etc. (optional step, if does not work)

Note: This works for me for my project that is configured with .kts files and do it with precautions.

Ric17101
  • 1,063
  • 10
  • 24
11
  • Crean project
  • Invalidate cache
  • Synce gradle project again. It will be fixed!
Viroth
  • 429
  • 5
  • 14
  • it wasn`t, in my case I had to upgrade Android Studio. (Help -> Check for updates). Now I have electric eel version. Much better performance, better build times. I updated everything, gradle plugin, libraries, etc. – Daniel Cettour Feb 10 '23 at 13:08
3

I have commented

include ':app'

and it allowed me to build my project

Denys Shabelnyk
  • 125
  • 2
  • 11
  • After clearing the cache, delete the build folder, and restart AS. I commented out this line and tried to sync, and it fails, then I uncommented it, synced, and it worked. – Quimbo Jan 23 '23 at 02:36
  • @Quimbo There is no `:app` in my `settings.gradle` but I am having the same error after upgrading from Android Studio `2021.3.1` to `2022.1.1`. Attempting to `Sync Project with Gradle Files` results in Sync error. I then `Invalidate Caches` (all of them) and restarted AS, and also deleted all `build` folders, but I am still getting Sync failed. Any idea how I can solve this? – WebViewer Jan 24 '23 at 09:39
  • 1
    @WebViewer Try to add the settings.gradle to your root project and add this to the file. `include ':app' rootProject.name = "root-project-folder-name"` – Quimbo Jan 25 '23 at 04:41
  • Thank you @Quimbo. I lucked out yesterday and managed to find the solution on my own. It wasn't trivial at all. I documented the process, as it is possible that others will encounter this, too: https://stackoverflow.com/a/75221722/2597758 – WebViewer Jan 25 '23 at 06:41
  • For me my project was missing include ':app' and when i added it , it worked and built successfully. Because of this i checkd it – Alix May 19 '23 at 14:02
0

delete folders build,.idea,.gradle and resync or Invalidate Caches / Restart

ayoub Cyb
  • 41
  • 3
0

Works for me, but you needed to Update and Clean build everything first to proceed.

PS: I was using Android Studio Flamingo 2022.2.1

-1

These steps helped me :

  1. delete folders [build, .idea, .gradle]
  2. resync or Invalidate Caches / Restart
  • after that restore deleted folders from Recycle Bin back cause project became corrupted. After that project works and can be build
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
-3

this works for me delete folders [build, .idea, .gradle] resync or Invalidate Caches / Restart and do the same steps by removing include ':app', etc.

Nabi
  • 1
  • 1