Android: Including multiple Java Packages to Manifest

前端 未结 5 973
执笔经年
执笔经年 2020-12-05 04:22

The app I am developing has many activities organized into seven java packages. Originally I wrote all the coding and stuff for each group of activities in a java package as

5条回答
  •  广开言路
    2020-12-05 05:07

    Android automatically creates the class named "R" in the package declared in your App's manifest. When all of your classes are inside that package, you'll never have to explicitly import "R". However, if you have classes in other packages, they won't see it by default and you will have to include

     import .R;
    

    or

     import .*;
    

    (substituting the actual name for of course).

    If you include library projects in your App, then they can reference their own "R" classes, which will be generated within their home packages. If you have several independent activities which need to be bundled together into one final App, you should seriously consider using library projects instead of manually merging things. It could make life much easier for you.

提交回复
热议问题