Monday, December 21, 2009

Howto setup a android project in Eclipse that access both Java and C/C++ code

If you follow the instructions on you will only have a Java project and will only see the C/C++ project files as 2:nd class citizens without any indexing. I will propose a another solution that will combine the ideas from
1. Copy the already available Java setup
$ cd <your mydroid folder>
$ cp development/ide/eclipse/.classpath .
# You might need to make the copy writable (describe on 
$ chmod u+w .classpath 
2. From Eclipse create a new C++ project File -> New -> Other, select C/C++ -> C++ Project give it a project name and uncheck "Use default location"
and give it the path to your directory (often called the mydroid dir)
Select Project Type: "Makefile project" -> "Empty Project", let the "-- Other Toolchain" be selected and press "Finish"

3. Add in Java to the same project
Close Eclipse as you will edit a file it holds open and will overwrite otherwise Now a /.project file has been created open it in a text editor and add the following:
as described here:
<?xml version="1.0" encoding="UTF-8"?>
    <name>android zoom2</name>
------------------------------- below is added 
------------------------------- end of the added stuff 
------------------------------- below is added 
------------------------------- end of the added stuff 
Now start eclipse again, now the Java classes are available in "Project Explorer" view and C/C++ files in "C/C++ Projects" view.

One problem remain when you build it will use "make all" and that will not work and need to be changed to "make" this can be done if you right-click on the project and select "Properties"
In the "Properties" window select "C/C++ Build" and click on the "Behaviour" tab and remove "all" from all the places where available.

I still used the java heap enlargement in eclipse.ini from the first link by changing the numbers in eclipse.ini to the numbers below:

The standard eclipse from Ubuntu 9.10 (installed from synaptic) uses this file /usr/lib/eclipse/eclipse.ini you need to be root to edit it e.g.

$ sudo gedit /usr/lib/eclipse/eclipse.ini


2010-12-08 Edit: removed wrongly formated spaces around < and >


  1. This comment has been removed by the author.

  2. Really good.
    Acooding to this article, I made android project.
    But the code in C or C + + trace (same as pressing F3 key in eclipse), it does not.
    Please help me.

  3. "But the code in C or C + + trace (same as pressing F3 key in eclipse), it does not."

    How do you mean? I get tranfered to the declaration when pressing F3 is that not working on your setup. I assume you have waited the "long" time it takes for indexing all c/c++ files.


  4. Nice work and you explained it really well. C++ in Urdu