14

I'm trying to get an (inherited) Android project to build. I'm using Ant & command line tools (and IDEA).

In styles.xml, there are references that cannot be resolved such as:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">

This is the original error I ran into:

[...]/res/values/styles.xml:8: error: Error retrieving parent for item:
No resource found that matches the given name '@style/Theme.AppCompat.Light'.

I then noticed that project.properties has this appcompat reference which is broken on my (OS X) machine:

target=android-18
android.library.reference.1=../../../../adt-bundle-linux-x86_64/sdk/extras/android/support/v7/appcompat

I tried to fix that by making the reference relative to ${sdk.dir}:

android.library.reference.1=${sdk.dir}/extras/android/support/v7/appcompat

So now that path should be correct. But now when I run ant debug:

BUILD FAILED
/opt/android-sdk-macosx/tools/ant/build.xml:573: 
  /opt/android-sdk-macosx/extras/android/support/v7/appcompat resolve to a 
  path with no project.properties file for project /Users/joka/devel/project/

So, any ideas? What's the simplest way to get this project built?

(Please note that Ecplise-specific advice won't be useful to me.)

Edit: The Android SDK installation looks like this:

enter image description here

Jonik
  • 80,077
  • 70
  • 264
  • 372
  • 1
    Do you have the support package in `/opt/android-sdk-macosx/extras/android/support/`? – Rajesh Aug 13 '13 at 12:52
  • @Rajesh: Yes, I do. And more specifically `/opt/android-sdk-macosx/extras/android/support/v7/appcompat/` seems to be installed just fine. – Jonik Aug 13 '13 at 13:24

3 Answers3

9

As Jay indicated, only relative paths will work on Unix/Mac.

For the Ant build to work, I also needed to generate build.xml for the appcompat project, using the command android update project -p <dir>, in my case:

/opt/android-sdk-macosx/tools/android update project 
    -p /opt/android-sdk-macosx-r22.0.1/extras/android/support/v7/appcompat

The exact config for me was:

android.library.reference.1=../../../../../../../opt/android-sdk-macosx/extras/‌​android/support/v7/appcompat

(This also works in local.properties, which I think is a better place since the same path won't work for all developers.)


I merely promoted my comment from 6 months ago into an answer as someone suggested.

By the way, now that I actually know something about Android development, I'd urge anyone who has the chance to ditch Ant and look into the new Gradle-based build system which is totally sweet in comprarison. It is CI-friendly and makes it easy to automate useful things (like using different package name and app icon for different build types). Stack Overflow will help when you run into problems.

Using the support libraries with Gradle, you'd skip all the above hassle and simply do:

dependencies {
    compile "com.android.support:appcompat-v7:18.0.+"
}
Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372
  • I also needed to change target=android-19 to target=android-21 in /opt/android-sdk-macosx-r22.0.1/extras/android/support/v7/appcompat/project.properties as described by http://stackoverflow.com/questions/26457096/appcompat-v7-r21-returning-error-in-values-xml – Matthew Grivich Jul 30 '15 at 22:05
6

I ran into the same problem, so I tried using a relative path and that fixed the problem for me. It looks like only relative paths work with android.library.reference. I did a quick search to verify this, and came across this stackoverflow link which indicates that absolute paths will work with android.library.reference on Windows, but not on Unix or Mac.

Peace.

Community
  • 1
  • 1
Jay
  • 271
  • 2
  • 6
  • Ah, indeed. I got it working with `android.library.reference.1=../../../../../../../opt/android-sdk-macosx/extras/android/support/v7/appcompat` This also works in `local.properties`, which I think is a better place since the same path won't work for all developers. – Jonik Aug 14 '13 at 07:52
  • 9
    (Additionally, for the Ant build to work, I needed to [generate build.xml](http://stackoverflow.com/a/15718940/56285) for the appcompat project, using `/opt/android-sdk-macosx/tools/android update project -p /opt/android-sdk-macosx-r22.0.1/extras/android/support/v7/appcompat`.) – Jonik Aug 14 '13 at 07:52
  • I put a symlink in my project dir `root => /` and then I can have absolute paths be relative paths :) – singpolyma Feb 18 '14 at 22:12
  • @Jonik You should add your comment as an answer. It is exactly what worked for me. – Code-Apprentice Feb 26 '14 at 22:44
  • @Code-Guru: [Done](http://stackoverflow.com/a/22055791/56285). Thanks for the idea! – Jonik Feb 26 '14 at 23:36
0

Your path seems to be wrong (you are missing the 'compatibility' part). The v7-appcompat library is at

{sdkpath}/extras/android/compatibility/v7/appcompat

for me (SDK Tools version 22.0.5 on Max OS X 10.7.5)

Patrick
  • 4,720
  • 4
  • 41
  • 71
  • 1
    Hmm, for me, `{sdkpath}/extras/android` contains only `support` and `m2repository` subdirectories. (And `{sdkpath}/extras/android/support/v7/appcompat` seems to be exactly what I need.) If I'm missing some part of the SDK, how exactly should I install it? I'm also using Android SDK Tools 22.0.5. – Jonik Aug 13 '13 at 13:28
  • Have you got the current version of the support libraries installed? (We are at version 18 at time of this comment) You can check by running the GUI of the SDK Update manager (execute the 'android' program in the tools subdirectory.) The support library is for me almost at the bottom of the list. – Patrick Aug 13 '13 at 13:38
  • Yeah, [according to Android SDK Manager](http://i.stack.imgur.com/adUuX.png) I do have Android Support Library, rev 18 installed. – Jonik Aug 13 '13 at 13:50
  • My apologies - apparently the SDK maintained an old path pattern for me (maybe to not break existing projects). When I un- and reinstalled it, it moved to your path without the 'compatibility' directory. So that does not seem to be the issue here... Sorry. – Patrick Aug 13 '13 at 14:07