R.java 中由 android 工作室创建的大量项目

Tons of items in R.java created by android studio

这是我第一次使用 Android studio。但是当我用它来创建我的第一个项目时,我发现在R.java(位置是app/build/source/r/debug/com.example.myapplication) 开头是这样的:

public final class R {
    public static final class anim {
        public static final int abc_fade_in = 0x7f040000;
        public static final int abc_fade_out = 0x7f040001;
        public static final int abc_slide_in_bottom = 0x7f040002;
        public static final int abc_slide_in_top = 0x7f040003;
        public static final int abc_slide_out_bottom = 0x7f040004;
        public static final int abc_slide_out_top = 0x7f040005;
    }
    public static final class attr {
        public static final int actionBarDivider = 0x7f01005a;
        public static final int actionBarItemBackground = 0x7f01005b;
        public static final int actionBarPopupTheme = 0x7f010054;
        public static final int actionBarSize = 0x7f010059;
        public static final int actionBarSplitStyle = 0x7f010056;
        public static final int actionBarStyle = 0x7f010055;
        public static final int actionBarTabBarStyle = 0x7f010050;
        public static final int actionBarTabStyle = 0x7f01004f;
        public static final int actionBarTabTextStyle = 0x7f010051;
        public static final int actionBarTheme = 0x7f010057;
        public static final int actionBarWidgetTheme = 0x7f010058;
        public static final int actionButtonStyle = 0x7f010072;
        public static final int actionDropDownStyle = 0x7f01006d;
        public static final int actionLayout = 0x7f01002c;
        public static final int actionMenuTextAppearance = 0x7f01005c;
        public static final int actionMenuTextColor = 0x7f01005d;
        public static final int actionModeBackground = 0x7f010060;
        public static final int actionModeCloseButtonStyle = 0x7f01005f;
        public static final int actionModeCloseDrawable = 0x7f010062;

它列出了太多的项目,如果我把它们放到 Word 中,它们将以 11 种字体大小填满 38 页。我试过删除它们,重建它们,重新启动,创建另一个项目,但它们仍然存在。我用过 Eclipse,所以我知道它应该是什么样子。有什么问题?是Gradle还是Android工作室本身造成的?

删除、重建、重启都不是你应该采取的正确做法。 这些行由 Android 支持库生成。

Including the Support Libraries in your Android project is considered a best practice for application developers, depending on the range of platform versions your app is targeting and the APIs that it uses. Using the features the libraries provide can help you improve the look of your application, increase performance and broaden the reach of your application to more users. If you use the Android code template tools, you will notice that all the Android application templates include one or more of the Support Libraries by default.

[1] http://developer.android.com/tools/support-library/index.html

但是,我不明白你为什么要摘掉它们。

R.java 是由 android AAPT(Android 资产打包工具)自动生成的文件。它具有一定的意义,对于 res 文件夹中的每个资源,都会自动创建一个相应的静态整数字段。 所以不管你删除多少次,它都会重新生成。 如果您想减少 R.java 文件中的行数,请尝试删除 res 文件夹中的一些值。

您拥有的布局文件、小部件和图像以及其他资源越多,R.java 文件的长度就会增加。

希望这能解答您的疑惑。