0

So I'm trying to make myself a little alarm clock app to learn android. Just to do some things that I've always wanted in an alarm clock, and have it be my own. Motivations aside, after coding the interface and a bunch of other functions, I've decided to borrow a bunch of the code, if not most, of the android alarm clock source.

I've already brought in all the res stuff, and I've included all the src files under their original com.android.alarmclock namespace so that they can still reference each other properly. However it refuses to generate the R file for the new files.

When I clean and rebuild and all that, it still generates a build file and an R file for the stuff in my package (com.nathantempelman.alarmapp) but I still get an error on all the android AlarmClock files.

Should I be changing the AlarmClock files so that they reference the R from my package somehow? Or did I miss something when I updated the AndroidManifest file that is stopping another R from building or something?

Or is it something else entirely? Is it a stupid idea to try to drag another application's source into mine? Should I open it up in an external project and try to reference it somehow?

I'd love to hear some ideas, if anyone has had a similar situation. Thanks for reading.

NathanTempelman
  • 1,301
  • 9
  • 34

2 Answers2

1

That is not how it's done. You want your Alarmapp to extend ALarmClock or extend the ALarmCLock classes or interfacces you want or need.

You can't drag source code in like that without re-factoring and tieing up all the loose ends, hence alarmApp extends AlarmClock.

Take a look here Hope this helps

apesa
  • 12,163
  • 6
  • 38
  • 43
  • I know how inheritance and interfaces work, but that wouldn't work for this. What I've coded isn't even alarm stuff, it's sort of like a front page. I want to borrow the entire alarm app, add things to it that I like, and have the front page of my app have a button to open it up. My problem is just getting it to build in the same project space so I can work with it. I'm still a little fuzzy about the whole generated files and R thing. Not sure if each activity in an application needs its own R, or they're supposed to share one big resource file or what. Any idea on any of that? – NathanTempelman Jan 27 '13 at 01:54
  • You will just need one resource file, R.java files are different. http://stackoverflow.com/questions/2048415/magic-behind-r-java-file If you just want to pirate some code you will need to Build it into your Activity / Class files yourself. It is easier to get ideas about various implementation techniques from others code as opposed to actually trying to use it. – apesa Jan 27 '13 at 02:07
0

I tried the library method, but that didn't work. In the end, I ended up just dropping the smaller project into the bigger project, combining the strings xml and android manifest, changing the intent classes of the activities in the android manifest, and dragging all the relevant pictures in. Quite a bit of work in the end, but it can be done.

Quick checklist:

  • Splice android manifest files - if the package names are different, make sure the package name at the top of your manifest only extends as far as both packages are the same

  • Make sure all the resources make it over

  • Splice the strings.xml, styles.xml, and anything else that is common between the two projects

Thought I'd post this in case someone else tries to do the same thing eventually. Best of luck

NathanTempelman
  • 1,301
  • 9
  • 34
  • I applaud your persistence, but all you did was circumvent all that is object oriented in favor of reinventing the wheel. While it works, you still went about it all wrong. But then again that is what learning is all about. – apesa Feb 12 '13 at 18:48
  • On the contrary, I did all this work to avoid reinventing the wheel. I'm not arrogant enough to believe I could code a better alarm than a team of experienced google developers, so I borrowed the relevant parts from their clock application. – NathanTempelman Feb 12 '13 at 21:40