Repository navigation
Problems with "id" package name prefix #1323
Description
Activity
Unfortunetaly this is a little bit more complicated.
When we process your code, we do not know what way you passed the menu id, we only get the integer value. So if we want to know the R.xxx.yyy field, we have to scan the R classes and find the value you passed.
We could just use the value itself, but we have to get the field for two reasons in this case:
- before generating code, we always validate the usage of the annotation, so we do not generate not compilable or not working code, but add a compile time error message instead. In this case, we have to be sure that the integer value indeed corresponds to a menu.
- We want to generate as nice and readable code as possible. That's why we use the R.xxx.yyy constants in our generated code, not just simply the passed value.
However, the imports are fully created by our Java code generator dependency,
codemodel. Unfortunately it has that bad import strategy, which leads to a non-compilable code in your case. I am afraid we cannot configure it.Alright, that is understandable.
For posterity, if anyone runs into this problem, I ended up sidestepping the issue by copying over the generated code from Activity_.java and changed the inflate() line which only adds some 4 or so lines of code so it's not too big a deal.- changed the title
[-]Cannot use @OptionsMenu: cannot find symbol[/-][+]Problems with "id" package name prefix[/+]on Feb 23, 2015 Thanks for sharing the workaround us and for pointing out the problem in the first place.
I am closing this issue for now, because there is no way to fix this currently. 😢
@larvyde sorry, but can you explain the problem here again?
I tested this, and this code was created:
import id.androidannotations.gradle.R.id; // ... @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId_ = item.getItemId(); if (itemId_ == id.myItem) { myItemSelected(); return true; } return super.onOptionsItemSelected(item); }
While this is ugly, but compiles and works. What is your exact problem?
as far as i understod his issue it is caused by R.menu usage.
AA imports id.co.packagename.R.id so when it tries to inflate(id.co.packagename.R.menu.logout) java thinks the 'id' in the package name is the generated resource class R.id.
Thanks @dodgex, now i can reproduce the issue with the following annotated class:
@OptionsMenu(R.menu.menu) @EActivity(R.layout.main) public class HelloAndroidActivity extends Activity { @OptionsItem(R.id.myItem) void myItemClicked() { } }
The good news is maybe this can be fixed by #1489.
Opened issue against jcodemodel phax/jcodemodel#30.
Should be fixed by #1566.
This happens when I tried using @OptionsItem on my app which happens to have a package name that starts with id. AA imports id.co.packagename.R.id so when it tries to inflate(id.co.packagename.R.menu.logout) java thinks the 'id' in the package name is the generated resource class R.id. I can't change the package name since it's tied to the company domain (indonesian domains have the ccTLD .id).
Since AA imports R.id, R.layout, etc, why doesn't it import R.menu as well, which would solve this? Either that or don't import anything and just use the fully qualified name (it's generated code anyway).
I'm using version 3.2. I apologise if this had been fixed in another version.