I'm following the stuff http://unity3d.com/support/documentation/Manual/Plugins.html and most pertinently the "Extending the UnityPlayerActivity Java Code" section. For the most part I think (crosses fingers) that I have things working. AndroidJNI calls are working. I'm successfully overloading the UnityPlayerActivity. But I'm getting this error during runtime; E/AndroidRuntime(15748): android.content.res.Resources$NotFoundException: Resource ID #0x7f020001 The R.java in my package in Eclipse has that resource ID. However when I look at the R.java in the StagingArea and it isn't there. And the resource itself also doesn't appear in StagingArea's res directory. I've looked at the contents of the jar I'm putting into Plugins/Android and the resource is there and the R.java has the resource ID. So what am I doing wrong or how do I get Unity to pull the resource information from from my package? Thanks. Let me know if any additional information is needed.
Additional Info: I'm on Unity 3.3.0f4 with Android Basic license I just created a new project from existing source in Eclipse and grabbed the stuff in the StagingArea. Then I dropped my source code into that and the missing resource and ran it as an android app. It worked and I'm no longer getting the error but this seems like a very poor workaround since, y'know, Unity will blow away the StagingArea every time I build and I'll have to go through the steps all over again. Anyone know the proper way of getting this working?
You follow the steps as given in integration of eclipse and unity3d in forum excluding last step i.e. 10th step. The android project you are using go to src.Then extends your activity as UnityPlayerActivity. Remove the setContentView(R.layout.main); it should work in eclipse ide.its working for me.If any error let me know the complete steps you follow for further help.
Thanks Milan this helped! Seems like I still need to jump through some hoops but your advice made me jump through fewer of them. It'd be nice if Unity could pull in the resources from stuff in Plugin/Android. Oh well. At least we can get it working.
Just wanted to post an update. I've continued pecking at getting it working from the Plugin directory to no avail. I tried loading it as an asset instead of a resource to no avail. Neither gets pulled into Unity. I've created a suggestion to have this fixed; http://feedback.unity3d.com/forums/15792-unity/suggestions/1678975-pullin-assets-and-resources-from-plugin-directory
Don't load resources based on their compile-time ID; use Activity.getResources().getIdentifier() to retrieve the ID instead.
Can this be stated in your docs please? Or is there any work around to handle this problem? Referring as strings makes the code hard to manage. Also, I see the code mentioned here still seems to refer with Id's which is conflicting your statement. Can you please confirm?
Considering it's almost a decade since I wrote that, I don't have all the details fresh in mind. But if I'm not mistaken this is an issue when using pre-compiled code, as the R.java effectively mismatches then. It could be my original statement is obsolete since the move to building via gradle..
Even with gradle build system, this issue holds. I understand that its because we are getting the library file where it has its own R.java class and once its merged with unity as it rebuilds again, it recreates the R.java. As of now we are loading based on string instead of using id to avoid the issue. But, if there are any ways possible to solve with id's (integers) instead it would be great. Any idea how other .aar files(google play libraries) able to solve this issue?
Again - my memory is fading (it's been several years since I touched the Android build process). But if I remember correctly .aar's include both pre-compiled classes (i.e. my_class_files.jar) but also the generated R.java in some kind of meta format (R.txt ? not sure). As such .aar's include more information than pure .jar's, and it's then possible to seed the final R.class with contents from the referenced libraries.
Sorry yes - I should've mentioned ; I've made the Unity Mobile/Android team aware of this thread. I hope they will be able to provide some more recent intel on the matter.