Search Unity

Android Plugin setContentView crash

Discussion in 'Android' started by Jon.W.Young, Aug 30, 2013.

  1. Jon.W.Young

    Jon.W.Young

    Joined:
    Dec 11, 2012
    Posts:
    2
    Hello,

    I made an Android Java plugin that accesses the camera + plays captured video and displays image overlays. It crashes whenever I dereference R:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(com.plugintest.R.layout.activity_song); // crash here

    This plugin works fine as a standalone android app and also when converted to a plugin for another android app. The problem only occurs when this is run as a Unity plugin. I can run the plugin from Unity and it won't crash so long as I don't dereference R.

    I manually copied the res folder to the Plugins/Android folder in the Unity project. I also copied the classes and R.txt files there.

    Any help or insight would be great. I've been stuck on this for 2 days and I'm pretty sure I read the entire internet looking for an answer. I'm new to both Unity and Android so I wonder if there's something fundamental I'm missing.

    Edit: I'm getting a NoClassDefFoundError. I think this is because the com.plugintest .jar doesn't contain the R class. The R class is created as a generated java file in a package of the same name (com.plugintest), but it doesn't get included in the .jar file that gets added to Plugins/Android. (I added the classes directory and the R.txt file in Plugins/Android but that hasn't helped).

    Edit 2: I finally discovered that R is not valid for a plug in. Using the Recources getIdentifier method did the trick.
     
    Last edited: Sep 16, 2013