2

I'm making a paid/free version of my app so have a 'Library Project' that the two apps use.

I'm trying to use Android Annotations to clean up my code: http://code.google.com/p/androidannotations/

Unfortunately when I use this in my shared library project, one of my projects gets the error in Eclipse: The type xActivity_ is already defined xActivity_.java /ProjectName/.apt_generated/lib/activities/

Because Android Annotations automatically creates a new activity with an extra '_' in the folder .apt_generated one of the apps is allowed to create this file, but the other gets the error "already defined".

Is there a way in Eclipse to resolve this? Or is it a problem with the Android Annotations?

Dennis Jaamann
  • 3,547
  • 2
  • 23
  • 42
reubenb87
  • 303
  • 4
  • 11

3 Answers3

3

This question is quite old, but I thought that I should mention android annotations now supports being used in libaries:

https://github.com/excilys/androidannotations/wiki/Library-projects

One caveat is that due to the way android library projects generate the R class, you cannot reference resouces directly inside the annotations. Eg, you cant do this:

@EActivity(R.layout.myLayout)
public class MyActivity extends Activity {

 @Click(R.id.myButton1, R.id.myButton2})
 public void someButtonClicked() {
 }
}

Instead you must do this:

@EActivity(resName="myLayout")
public class MyActivity extends Activity {

  @Click(resName={"myButton1", "myButton2"})
     public void someButtonClicked() {
  }
}
Luke Sleeman
  • 1,636
  • 1
  • 16
  • 27
3

This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker.

AndroidAnnotations wasn't designed with this use case in mind, but this is still a very valid use case. The problem seems to be that the activity is generated in the shared library project, when it should be generated in each depending project, am I right ?

(please answer in the bug tracker)

Pierre-Yves Ricau
  • 8,209
  • 2
  • 27
  • 43
  • Thanks for your input, I was going to submit to bug tracker, but just wanted to check if it could be fixed in eclipse. Yes the activity should be generated in the depending project, otherwise both of the depending projects are trying to generate the same activity in the same location. – reubenb87 Jul 20 '11 at 10:26
1

I just knew AndroidAnnotations (which seems a great tool!) but I think that if you do this using different projects (sharing the same library) your problem should be solved.

Pedro Loureiro
  • 11,436
  • 2
  • 31
  • 37
  • This is exactly what I have. An Android Libary project ProjectLib say, that has an activity using the AndroidAnnotations. But I have two projects that use this library, and one of them is able to build the project successfully. But the other has an error in Eclipse: The type xActivity_ is already defined xActivity_.java /ProjectName/.apt_generated/lib/activities/ I guess because it is trying to generate the same file which is already existing. Now I saw in the 'Annotation Processing' the path is set to '.apt_generated' should I change this for one of the projects? Sorry I can't be more clear! – reubenb87 Jul 07 '11 at 13:26
  • I haven't used AndroidAnnotations so I don't know how it works, but I think that if you go to eclipse and do File -> New -> Project, it shouldn't try to create files in the same folder. otherwise changing that path in one of the projects, if possible, should also solve the problem. Changing the namespace in one of the projects could also solve it. – Pedro Loureiro Jul 07 '11 at 13:43
  • unfortunately as both projects are using the shared library, they both try to create the same file, in the shared library. – reubenb87 Sep 15 '11 at 13:56