Search Unity

Android Plugin picture in res folder always mess up....

Discussion in 'Android' started by ZorroBlade, Dec 9, 2011.

  1. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    I often write Android Plugin to integrate others publisher's game SDK.

    I have met a bug twice, pics in res/drawable folder are right, when I write an simple Android Application in eclipse. But when I modify it to a Unity3D plugin , and build apk through Unity , the pics in res/drawable folder all mess up . Such as when a place need to use pic A,but pic B shows up instead of pic A.... :(

    I don't whether it is a Unity bug, or because I use eclipse...Sorry for my english , thanks for help!
     
  2. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    sorry for post the topic twice , forum administrator please help me delete the previous one , thank you very much!
     
  3. suzrik

    suzrik

    Joined:
    Apr 6, 2012
    Posts:
    1
    I have the same problem. Whether it was possible to you to solve it?
     
  4. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    The issue is, when you compile it (i.e export the jar) they are done correctly. But when unity3d builds the apk it will rebuild everything and they get a different id internally, while your Java code still reference the old IDs.

    The only two (?) workarounds are
    a) doing it like OpenFeint and put your plugins as library and reference it as library (instead of referencing a *.jar file)
    b) use .getIdentifier(...) to get the new ID instead of R.drawable.xxx

    Code (csharp):
    1.  
    2. // Normal Java code
    3. String desc = res.getString(R.id.description);
    4.  
    5. // turns into
    6. String desc = res.getString(res.getIdentifier("description", "string", "com.mycompany.MyGame"));
    7.  
     
  5. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    thanks for your advice. That really helps!!
    Now we have change to release the unity Android game using eclipse , cause most of the time the plugin of Unity3D Android is often provide by the third part team.
    So sometime the best way to avoid the problem is that.