Let’s assume you already have an Android project on your Mac.
Create the XCode Project
- start XCode
- select File > New Project…
- select External Build System
- go to the parent directory of your Android Project
- in the Save As: field, enter the directory name of your Android Project
- select the scarily-misnamed Replace option
Add Files
In your new XCode project:
- select first item in the left hand column, which is the name of your project
- right-click, select Add > Existing Files…
- select add files (don’t select the Copy option)
- organize as desired (I like to do a lot of grouping). You should be probably adding at least your Java files and your Layout resources.
Configure your Build Target
In your new XCode project:
- look for Targets
- inside will be a target for your project’s name
- double click on it
- change Build Tool to
ant - change Arguments to
install
- change Build Tool to
Clicking ⌘B should now compile your project.
Note: if you figure out how to have a Build vs. Build & Install (e.g. ⌘ENTER) please let me know!.
Getting XCode to Recognize Java errors
- Reconfigure the Build Target, changing
antto./xant - Make a file
xantin the project’s home directory, using the code below - do (from a Terminal)
chmod a+x xant
#!/usr/bin/env python
import sys
import re
import subprocess
av = list(sys.argv)
av[0] = "ant"
p = subprocess.Popen(av, stdout = subprocess.PIPE)
javac_rex = re.compile(" +[[]javac[]] +")
line_rex = re.compile("[.]java:[\d]+:")
pending = ""
while True:
d = p.stdout.read(128)
if not d:
break
d = pending + d
nx = d.rfind('\n')
if nx == -1:
pending = d
continue
else:
d, pending = d[:nx + 1], d[nx + 1:]
d = javac_rex.sub("", d)
d = line_rex.sub(r"\g<0> error: ", d)
sys.stdout.write(d)
sys.stdout.flush()
sys.stdout.write(pending)
p.wait()
sys.exit(p.returncode)
Note: this code has been updated from the original post. It now reads little chunks and outputs them immediately rather than post-processing the ant output.