I was looking through a sample project project provided by the android developer website and I see that a file Beam.java
has been declared in a package as package com.example.android.beam;
with the folder structure "..\src\com\example\android\beam\Beam.java". There are two other files, BuildConfig.java
and R.java
in a similar directory structure, but in a completely different directory "..\gen\com\example\android\beam\Beam.java" but with the same package declaration of package com.example.android.beam;
. Are all these files in the same package even though they are in different folders? Did the IDE put the latter two files in a different folder only to make it clear that they are autogenerated, or is there a another reason as well?
3 回答
The folder called "gen" is an automatically generated folder which contains files that are also automatically generated. In other words, don't worry about the "gen" folder, your packages and files and whatever you make will be in the "src" folder.
For example, the Android IDE generates the file "R.java" which contains the element id's used in your code, ie. "R.id.some_element", "R.string.some_string".
They are autogenerated so as you said, they are put in /gen/... . What YOU write must be put in /src/...
不同文件夹中的文件可以在同一个包中吗?
是的,只要它们都被编译并打包到 .dex 文件中的同一目录中即可。