3.1 resource lookups

First of all, thanks to the Unity team for getting 3.1 out the door so quickly and giving some much-needed features to the Android Platform.

I don’t think the resources are being built correctly, though. I have a number of layouts in a res/ folder in the Plugins/Android directory. It seems that the actual layouts are being found just fine, but when I go to look up something by its id it’s not able to find it.

For instance, this returns null. When I build it through eclipse, it works fine.

Button navButton = (Button)this.findViewById(R.id.buttonAbout);

I have found the same problem.
Root of problem (imho) is here: when you compile application under Eclipse the R.id.buttonAbout has one value (for example 0xF0000010). This value places into your .class file as integer constants. When you put your src+res into the unity plugins directory, your resources add to unity resources and repacked. And R.id.buttonAbout has another value (for example 0xF0000020) and your application can not find this resource by old id.

For examle:

1) Eclipse:
public final class R {
    public static final class drawable {
        public static final int bb_backboard=0x7f020000;
.........
        public static final int mylennsview_right_full=0x7f020019;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}


2) Unity:
public final class R {
    public static final class attr {
    }
    public static final class bool {
        public static final int profiler=0x7f060000;
    }
    public static final class drawable {
        public static final int app_icon=0x7f020000;
        public static final int app_splash=0x7f020001;
        public static final int bb_backboard=0x7f020002;
..............
        public static final int mylennsview_right_full=0x7f02001b;
    }
    public static final class id {
        public static final int inputLayout=0x7f070000;
        public static final int okButton=0x7f070002;
        public static final int txtInput=0x7f070001;
    }
    public static final class integer {
        public static final int gles_mode=0x7f050000;
        public static final int splash_mode=0x7f050001;
    }
    public static final class layout {
        public static final int input=0x7f030000;
        public static final int main=0x7f030001;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int done_button=0x7f040002;
        public static final int hello=0x7f040000;
    }
}

Exactly.
For Unity 3.1 you must copy files from Temp\StagingArea\res back to your Eclipse resource:
– drawable/app_icon.png
– drawable/app_splash.png
– layout/input.xml
– also add lines to string.xml:
Never give up
1
false
0

And this part of Unity quest will be passed ))

Yes, that was an oversight on our part. With the next release we have removed all but the standard app_name/app_icon resources. But you can also lookup resources by name:

int id = Activity.getResources().getIdentifier( name, type, Activity.getPackageName());

That’s how third party libs load their resources without relying on pre-generated resources IDs.