2

I am trying to build an Android app using Gradle on Ubuntu 18.04. Android Studio is not installed o the machine (I use Eclipse for development but maintain a gradle toolchain).

The toolchain has worked on a different machine running Ubuntu 16.04. However, it does not work with gradle 3.4.1, which ships with 18.04, so I had to upgrade my build config. On the 18.04 machine, I changed the dependency

classpath 'com.android.tools.build:gradle:2.1.2'

to

classpath 'com.android.tools.build:gradle:2.3.0'

and changed

buildToolsVersion "23.0.3"

to

buildToolsVersion "25.0.3"

Now when I run gradle build, I get the following error message:

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

However, I have ANDROID_HOME set and pointing to ~/bin/android-sdk-linux, which is the root dir of my Android SDK setup. Also, I have Android SDK build tools 25.0.3 installed locally.

What gives?

user149408
  • 5,385
  • 4
  • 33
  • 69
  • Open **local.properties** file in project root and check whether **sdk.dir=.../android_sdk** line is defined or not ? – Iamat8 Jun 18 '18 at 11:34
  • There is no local.properties file, I rely completely on `ANDROID_HOME`. – user149408 Jun 18 '18 at 11:41
  • what do you mean by `I rely completely on`, this file is auto created when you define sdk path – Iamat8 Jun 18 '18 at 11:42
  • As documented this file is used by Gradle to locate your android sdk, I think you are getting error as gradle could not find you sdk. – Iamat8 Jun 18 '18 at 11:45
  • The file doesn’t exist (I started this project on a different machine and then cloned the git repo, which shouldn’t contain any files with local configuration). My reading of the error message is that, without that file, Gradle will use `ANDROID_HOME` to determine the SDK path. However, after creating this file, the error seems to disappear (though I’m getting another, probably unrelated one). – user149408 Jun 18 '18 at 11:47
  • I think your `ANDROID_HOME` and `sdk.dir` are different.. can you check that? – Iamat8 Jun 18 '18 at 11:49
  • Just checked again, both contain the same path (I created the file with `echo sdk.dir=$ANDROID_HOME > local.properties`). – user149408 Jun 18 '18 at 11:51
  • you said you got new error, can you stat that ? – Iamat8 Jun 18 '18 at 11:52
  • `Failed to notify project evaluation listener. javax/xml/bind/annotation/XmlSchema` – user149408 Jun 18 '18 at 11:53
  • Please try disabling the Instant Run and Rebuild your project .. – Iamat8 Jun 18 '18 at 11:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173333/discussion-between-user149408-and-mohit). – user149408 Jun 18 '18 at 13:09

2 Answers2

2

Apparently Gradle does not honor ANDROID_HOME, despite the error message saying otherwise.

As a workaround,

echo sdk.dir=$ANDROID_HOME >> local.properties

in the project root dir has fixed this (after also ensuring I was using the correct JDK version and had all submodules checked out).

Oddly, however, on a different computer (also running Ubuntu 18.04) the same app builds without local.properties being present.

user149408
  • 5,385
  • 4
  • 33
  • 69
0

If there is no local.properties, just go ahead and create one in parallel to gradle directory.

Then add this line, sdk.dir=/Users/YOUR_USERNAME/Library/Android/sdk

Amol Jindal
  • 106
  • 4