views:

85

answers:

1

Hi there!

I just started to play with android dev and java+eclipse is pretty new to me. I managed to create simple project and run it on my device. Now I want to create simple game (more of them actually) and I would love to use shared code base for all of them (game loop, initialization, etc..).

Problem is that I have no idea how to correctly do this. I created android project called engine with all basic stuff that I need and made it work on device. Now I tried to create another project in same workspace called mygame. Main class (activity) of mygame is MyGameApp which inherits from EngineApp (main activity of my engine project) which inherits from Activity.

I added engine project into required projects in mygame build path tab in properties. Problem is that when I try to run this project it crashes on ClassNotFoundException trying to find my MyGameApp class.

Any help (or pointer to some articles that explain how this is done) is greatly appreciated. few hours of googling didn't help much :/

+1  A: 

You need to set up an Android Library Project

An Android library project is a development project that holds shared Android source code and resources. Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files. Multiple application projects can reference the same library project and any single application project can reference multiple library projects.

The docs go on to say how to convert an existing project to a library project:

You can also convert an existing application project into a library. To do so, simply open the Properties for the project and select the "is Library" checkbox. Other application projects can now reference the existing project as a library project.

Stephen Denne
thanks, that looks like it does what I need. However, I still have same problem, it can't find MyClassApp. I am not sure if there is error somewhere else as it complain about inherited class, not base EngineApp which would be logical if there was some problem with project dependecies and library linking
Lope
Not sure... try cleaning your projects, then editing a file in each (e.g. add white-space) to force a rebuild.
Stephen Denne
@lope did you add the library project using the Android properties screen shown in Figure 2, and remove it from the Project References screen?
Stephen Denne
I added library project just like Figure 2 said, but I forgot to remove it from Project preferences. Now when I did I can't compile because it can't find EngineApp from which I inherit. I will look at it again tomorrow, thanks for you help so far!
Lope
turns out I just forgot to import correct class :/ this is what happens when you get overdependent on IDE... and it was pretty late. Thanks again, you have been a great help
Lope