Search Unity

Resource Not Found

Discussion in 'Android' started by Fenyx4, Mar 15, 2011.

  1. Fenyx4

    Fenyx4

    Joined:
    Aug 5, 2010
    Posts:
    23
    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.
     
  2. Fenyx4

    Fenyx4

    Joined:
    Aug 5, 2010
    Posts:
    23
    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?
     
  3. Milan_cool

    Milan_cool

    Joined:
    Jan 24, 2011
    Posts:
    22
    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.
     
  4. Fenyx4

    Fenyx4

    Joined:
    Aug 5, 2010
    Posts:
    23
    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. :)
     
  5. Fenyx4

    Fenyx4

    Joined:
    Aug 5, 2010
    Posts:
    23
  6. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Don't load resources based on their compile-time ID; use Activity.getResources().getIdentifier() to retrieve the ID instead.
     
    Thhhhhhhhhhhhhh likes this.
  7. Thhhhhhhhhhhhhh

    Thhhhhhhhhhhhhh

    Joined:
    Aug 31, 2015
    Posts:
    1
    @eriQue

    Thank you. You saved my days...
     
  8. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    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?
     
  9. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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..
     
  10. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    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?
     
  11. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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.
     
  12. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,963
    @eriQue Can you link someone who can answer this if possible?
     
  13. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    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.
     
    Voxel-Busters likes this.