16

For years, I've used the Ant integration for Eclipse to build my Android projects as outlined by Google on this documentation page. It's my favorite way of building release builds, because I can simply hit "Run external tool" in Eclipse to start the Ant build, and it runs in the background.

Since recently (I believe ADT 22.0 or 22.1), I've been getting the following failure:

[echo] Handling Resources...
[aapt] Generating resource IDs...
[aapt] invalid resource directory name: C:\path\to\project\bin\res/crunch

BUILD FAILED
C:\Android\android-sdk\tools\ant\build.xml:653: The following error occurred while executing this line:
C:\Android\android-sdk\tools\ant\build.xml:698: null returned: 1

I'm not sure what the cause of this is, since AAPT seems to generate the "crunch" directory itself. I've tried cleaning my project and disabling automatic building in Eclipse but to no avail.

I also tried executing ant release outside of Eclipse, but this gives the same error. Executing ant clean release doesn't work either, as it attempts to delete jars that are still in use by Eclipse. Therefore, the only solution that I've found to work at all is:

  1. Exit Eclipse
  2. Wait for the process to end
  3. Execute ant clean release

This is excruciating because as we know, restarting Eclipse is a royal pain. Furthermore, all affected projects need to be cleaned which makes the entire process take up to half an hour. I've opened issue #60496 on b.android.com, but haven't heard any official response.

Is there any solution to this aside from biting the bullet and switching to Android Studio?

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • I'm seeing this too but only for projects which refer to a library project. From the issue you raised, it appears to be the same for you, although you don't mention it here. Can you confirm that this is the case? – NickT Dec 19 '13 at 11:46
  • @NickT Yes, the project in question references numerous library projects. – Paul Lammertsma Dec 19 '13 at 12:18
  • 1
    I've been using Ant builds for ages but I can't get my head round this bug, none of the workarounds fix it for me, so I'm starting a bounty on this. If closing Eclipse fixes it for you, might closing a few projects save you some time? Just a thought. – NickT Dec 19 '13 at 12:36
  • It's not silver bullet, and it's not actually addressing your actual question, the AAPT problem, but at least savse you the hassle of having to exit eclipse. You can try to use handle.exe (from pstools) so you can remove the file locks without needing to exit eclipse. (check http://www.timstall.com/2009/02/killing-file-handles-but-not-process.html). I've had similar problems when using eclipse + windows and this little tool was a life saver! – pabrantes Dec 19 '13 at 12:55
  • @NickT I've done this in the past with Process Explorer, but it's my understanding that forcefully closing file handles is potentially very dangerous as the pointer may be reused for an entirely different file and may possibly corrupt system files. I don't know if that's just a myth, but I'd rather not run the risk of a much bigger problem. As for simply closing projects: no, it's the same problem as Eclipse is still holding on to the jars. It would appear that this is a bug, as that certainly shouldn't be happening. – Paul Lammertsma Dec 20 '13 at 10:07
  • As a commenter in the issue also says: have you tried setting a different build dir for eclipse so that it does not conflict with the ant build? – flup Dec 26 '13 at 09:11
  • What is in build.xml around the line mentioned in the error message? – Harald Dec 26 '13 at 09:16
  • My solution is to shift+delete the bin and gen the folder, then rebuild it again. It's still a pain. – dieend Jan 14 '14 at 13:06

9 Answers9

5

The answer is here:

http://pissedoff-techie.blogspot.in/2014/07/android-build-fails-with-ant-on-eclipse.html

  1. Disable autobuild.
  2. delete crunch folder.
  3. run ant script.
  4. re enable auto build.
Utsav Gupta
  • 3,785
  • 5
  • 30
  • 52
2

Also from https://code.google.com/p/android/issues/detail?id=60496, I just deleted gen/* and bin/* in the project and it's referencing library. It worked.

0

I had a similar error on a Linux machine. It turns out that aapt uses the 32bit emulation libraries, and if they fail for some reason then the build process can fail mysteriously at this location in build.xml.

In my case the reason for the failure was CircleCI had to patch their kernel to blacklist a newly found vulnerability in a 32bit emulation API. They were then able to patch their kernel to eliminate the vulnerability within a couple of days.

JohnnyLambada
  • 12,700
  • 11
  • 57
  • 61
0

On OSX I just cleaned the project and rebuilt and that worked for me.

Project > Clean (pick your project name)

David Dehghan
  • 22,159
  • 10
  • 107
  • 95
  • 1
    If I clean the project in Eclipse and execute `ant release` I get the problem described in the OP. As described elsewhere, performing `ant clean release` is insufficient on Windows, and only works on Linux if automatic building is disabled. – Paul Lammertsma Apr 17 '14 at 22:09
0

If you are running ant from command line use command 'ant clean release' instead of just 'ant release'. If you are using eclipse disable autobuild delete crunch folder and then execute ant more info : http://pissedoff-techie.blogspot.in/2014/07/android-build-fails-with-ant-on-eclipse.html

Utsav Gupta
  • 3,785
  • 5
  • 30
  • 52
0

I tried the solutions here such as: restarting eclipse, clean the project and rebuild, removing crunch folder and run ant again etc. After running ant script (from eclipse) it seems that ADT interferes and generates crunch folder repeatedly. The workaround for me was just to run ant from command line. Initially i had to execute the following steps to remove the crunch folder:

  1. Disable Build Automatically option from Project menu.
  2. Manually remove the cruch folder.
  3. Run ant clean release from command line.
eldjon
  • 2,800
  • 2
  • 20
  • 23
  • This solution is already mentioned both in the question and top answer. – Paul Lammertsma Sep 18 '14 at 13:25
  • where is that mentioned in the question? question says that ant clean release does not work.thats all abt it. my point was to keep Autorebuild disabled and use ant from command line. thats how i did at least – eldjon Sep 18 '14 at 14:14
  • The associated issue mentions that solution in [comment #2](https://code.google.com/p/android/issues/detail?id=60496#c2). I had originally posted this question as that particular solution doesn't suffice for Windows due to file handles. I have since switched to Linux, so I don't know if the problem with file handles has been resolved. – Paul Lammertsma Sep 18 '14 at 14:30
  • I see I was confused as the former top answer has since been deleted by the owner. – Paul Lammertsma Sep 18 '14 at 14:32
0

Hi try this line and build it again.

rm -fR $(find . -type d -name crunch|xargs)
Chen-Tsu Lin
  • 22,876
  • 16
  • 53
  • 63
Calvin F.
  • 1
  • 1
0

I also had same kind of issue. I manually deleted 'bin' and 'gen' folders of the library and tried. It worked for me.

jrh
  • 764
  • 13
  • 31
0

Add this line into top of the custom_rules.xml

<delete dir="../YourLibraryName/bin/res/crunch"/>

if do not have custom_rules.xml, create one and put this into the file. Place the custom_rules.xml within your project dir.

<?xml version="1.0" encoding="UTF-8"?>

<project name="imported" >

<delete dir="../YourLibraryName/bin/res/crunch"/>

</project>

UPDATE

It can be done by adding following line in library project build.xml.

   <delete dir="${out.absolute.dir}"/res/crunch />
Clevester
  • 169
  • 1
  • 4