Gradle sync issue on Debian OS due to user does not have permission

Cross references

  1. Android Gradle Plugin 3.0+ sync issue
  2. Gradle proxy configuration

I have written an article about all the proxies that should be configured properly in order for gradle working behind a network proxy (See Gradle proxy configuration). However, sometimes even though you are pretty sure that all the proxy settings, i.e. the gradle.properties, bash proxy and maven proxy, have been configured but you still cannot make your gradle synchronise, e.g. on Debian OS. Probably the confusing gradle log will be like below:

Task :xxxxxxx:compileDebugAndroidTestAidl
17:03:22.138 [DEBUG] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-3: Shutdown connection
17:03:22.139 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Connection discarded
17:03:22.139 [DEBUG] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-3: Close connection
17:03:22.139 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 3][route: {tls}->http://your-proxy-xxx.com:8080->https://jcenter.bintray.com:443%5D%5Btotal kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 20]
17:03:22.140 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation ‘Download https://jcenter.bintray.com/com/android/support/support-annotations/maven-metadata.xml
17:03:22.147 [DEBUG] [org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor] Constructing external resource: https://dl.google.com/dl/android/maven2/com/android/support/support-annotations/maven-metadata.xml
17:03:22.148 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation ‘Download https://dl.google.com/dl/android/maven2/com/android/support/support-annotations/maven-metadata.xml‘ started
17:03:22.148 [DEBUG] [org.gradle.internal.resource.transport.http.HttpResourceAccessor] Constructing external resource: https://dl.google.com/dl/android/maven2/com/android/support/support-annotations/maven-metadata.xml
17:03:22.148 [DEBUG] [org.gradle.internal.resource.transport.http.HttpClientHelper] Performing HTTP GET: https://dl.google.com/dl/android/maven2/com/android/support/support-annotations/maven-metadata.xml
17:03:22.149 [DEBUG] [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: default
17:03:22.149 [DEBUG] [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in the context

17:03:30.371 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] DaemonExpirationPeriodicCheck running
17:03:30.371 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
17:03:30.372 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
17:03:30.372 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
17:03:30.372 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
17:03:30.372 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
17:03:30.372 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.

17:03:22.246 [null] [org.gradle.internal.progress.DefaultBuildOperationExecutor]

As you can see in above logs, the gradle synchronisation process is blocked by a network action, i.e.

17:03:22.139 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 3][route: {tls}->http://your-proxy-xxx.com:8080->https://jcenter.bintray.com:443%5D%5Btotal kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 20]

And afterwards, the gradle daemon keeps printing the “Waiting …”, “Lock …” and “Releasing …” logs. This log has ever led me to the direction that my gradle proxies are not properly configured which cause the gradle cannot connect to maven repos. However, after a few days of hard work, i figured out that this log actually is not the proxy issue but the user permission running the gradle commands. I ever ran my gradle commands using “sudo” and some directories are created and owned by “root” user. Next time when I try to run gradle commands using normal linux user, then these directories are not accessible by normal user. What is confusing is that the gradle log never tells you any information about the user permission but just keep printing above duplicate logs.

The solution to this is as below.

  • To find all the files and directories that are owned by root or belong to root group:
    $ls -alR | grep -w root > list.txt

    The result of this command will be output to file list.txt, open it to check all the files and directories. For example you may see the output something as below:

    drwxrwxr-x+ 86 root  admin   2.9K Jun 29 20:30 Applications/
    drwxr-xr-x+ 65 root  wheel   2.2K May 19 00:19 ***/.gradle
    drwxr-xr-x@  2 root  wheel    68B Nov 20  2016 ***/build
    drwxr-xr-x@  4 root  wheel   136B Jun 29 20:31 .gradle
    drwxr-xr-x    3 employee  staff   102B Nov 10  2015 Samsung/
    drwxr-xr-x    7 employee  staff   238B Jul  6  2016 VirtualBox VMs/
    drwxr-xr-x    3 employee  staff   102B Nov  4  2016 android-ndk/
    drwxr-xr-x    3 employee  staff   102B Aug 31  2016 bin/
  • To find the exact location of those files or directories
    $find "$PWD" | grep your-file-name
  • Delete those files or directories.
    $ sudo rm -rf your-file-name

Usually, you need change your directory to below locations to perform above actions to delete all the files with root user.

  • ~/.gradle – The .gradle cache under your user’s “Home” directory
  • <project-root>/.gradle – The .gradle cache under your project root directory
  • <project-root>/<module>/build – The .gradle cache under your gradle module directory.
  • ~/.m2 – The Maven cache directory under your user’s “Home” directory

Then start over a gradle sync, the problem should be resolved.

 

 

2 thoughts on “Gradle sync issue on Debian OS due to user does not have permission

  1. Pingback: Gradle proxy configuration – Arophix

  2. Pingback: Android Gradle Plugin 3.0+ sync issue – Arophix

Leave a comment