Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Problems with "id" package name prefix #1323

Description

@larvyde

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.

Activity

  1. WonderCsabo commented on Feb 16, 2015

    @WonderCsabo
    Member

    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.

  2. larvyde commented on Feb 18, 2015

    @larvyde
    Author

    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.

  3. changed the title [-]Cannot use @OptionsMenu: cannot find symbol[/-] [+]Problems with "id" package name prefix[/+] on Feb 23, 2015
  4. WonderCsabo commented on Mar 22, 2015

    @WonderCsabo
    Member

    Thanks for sharing the workaround us and for pointing out the problem in the first place.

  5. WonderCsabo commented on Jun 17, 2015

    @WonderCsabo
    Member

    I am closing this issue for now, because there is no way to fix this currently. 😢

  6. WonderCsabo commented on Jul 8, 2015

    @WonderCsabo
    Member

    @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?

  7. dodgex commented on Jul 9, 2015

    @dodgex
    Member

    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.

  8. WonderCsabo commented on Jul 9, 2015

    @WonderCsabo
    Member

    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() {
    
        }
    }
  9. WonderCsabo commented on Jul 9, 2015

    @WonderCsabo
    Member

    The good news is maybe this can be fixed by #1489.

  10. WonderCsabo commented on Sep 14, 2015

    @WonderCsabo
    Member

    Opened issue against jcodemodel phax/jcodemodel#30.

  11. yDelouis commented on Oct 6, 2015

    @yDelouis
    Contributor

    Should be fixed by #1566.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions