2

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?

4

3 回答 3

2

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".

于 2013-07-25T02:17:55.617 回答
1

They are autogenerated so as you said, they are put in /gen/... . What YOU write must be put in /src/...

于 2013-07-25T02:14:06.207 回答
1

不同文件夹中的文件可以在同一个包中吗?

是的,只要它们都被编译并打包到 .dex 文件中的同一目录中即可。

于 2013-07-25T02:55:20.287 回答