0

We have a batch file to build our Android application. It basically runs gradlew.bat assemble. When I remote desktop into the build machine (Windows 8) and run the batch file, everything builds as expected. However, when I invoke the batch file through an NT service, we start getting errors.

The account that the service runs under does have administrative privileges on the machine.

The first error was javax.net.ssl.SSLHandshakeException. Based on another post Android Studio Gradle build failed. Error:Cause: peer not authenticated, I modified gradle-wrapper.properties to use http instead of https for the distribution url. That took care of this problem.

The next error was also similar but this time it was with downloading pom file. Based on another post android- Gradle: An issue occurred configuring root project android studio, I modified build.gradle to use http://jcenter.bintray.com/ as the url instead of default https.

Now I am getting the following error:

Could not parse POM    
http://jcenter.bintray.com/com/android/tools/build/gradle/1.1.0/gradle-1.1.0.pom

I am wondering why https could cause a problem in NT service account but not in normal interactive account. Is there a way to fix it? If not, would appreciate if someone has an insight on what the above error means. Regards.

Community
  • 1
  • 1
Peter
  • 11,260
  • 14
  • 78
  • 155

1 Answers1

0

A common source of problems when programs that execute successfully as an interactive user, but fail when run as a service, is the user settings surrounding the execution have changed. For example, when you run Gradle, there are settings in %USERPROFILE% \ .gradle (typically c:\users\<username>, which for you logged in interactively is different than the account under which the service is running.)

When you run as a service, there is a different user profile, or possibly none at all. Have your batch script dump the environment (add "set" near the top of the .bat file - this will dump an alphabetical list of environment variables), and compare the output when it runs as a service to when you run it interactively. See if USERPROFILE is defined, and if it is compare the .gradle folder in the service's area to your own .gradle folder.

In addition to Gradle settings, Gradle's cache is also typically under the .gradle folder. Your cache is likely to contain different items than the cache of the service, which may be significant if there are authentication issues in the external repositories to which your build tries to connect (again, possibly as a result of the different credentials in your user configurations!)

The tool processing the https request may look for certificates somewhere in your user profile. You may have accepted a certificate (used to 'recognize' an https server) that is not included in the accepted certificates of the service. These would likely be in the .keystore file in your user profile. Java's keytool.exe can help to decode and dump this file.

Other tools involved in your build may also have settings stored in the USERPROFILE space, which differ between your space and that of the service account - for example Android (.android), Java, Maven (.m2), Git (.gitconfig), etc.

John Elion
  • 1,323
  • 1
  • 16
  • 30