Search Unity

ClassNotFoundException on Android plugin

Discussion in 'Android' started by jvil, May 16, 2013.

  1. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    Hi,

    I'm trying to create an Android plugin, after following these steps: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html

    I get the following error when launching my game:

    My Android plugin is:

    Code (csharp):
    1. public class ActivityMain extends UnityPlayerNativeActivity {
    2.    
    3.     @Override
    4.     protected void onCreate(Bundle savedInstanceState) {
    5.         Log.d("DEBUG","On create success");
    6.         super.onCreate(savedInstanceState);
    7.     }
    8. }
    I really just only want to make sure onCreate is called correctly from my plugin. but it looks don't found my class and I'm really not sure why.

    Android manifest is:

    Code (csharp):
    1. <activity android:name=".ActivityMain" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="landscape">
    2.         <meta-data android:name="android.app.lib_name" android:value="unity" />
    3.         <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    4.         <intent-filter>
    5.             <action android:name="android.intent.action.MAIN" />
    6.             <category android:name="android.intent.category.LAUNCHER" />
    7.         </intent-filter>
    8.     </activity>
    and the plugin is installed on Assets/Plugins/Android folder.

    Any ideas?
     
    Last edited: May 16, 2013
  2. Raigex

    Raigex

    Joined:
    Jul 6, 2012
    Posts:
    154
    you ActivityMain.java file where do you create it (just a text file or inside an IDE).
    If inside an IDE do you export that project into a .jar file that you put inside your Assets/Plugins/Android folder?
    And finally what is the package name of the ActivityMain.java file
    is it the same as the package name for your Unity3D project or does it differ?
     
  3. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    I'm using Eclipse as IDE to export the .jar file. It's on package: com.testing.myproject, it seems found the package but don't found the class
     
  4. Raigex

    Raigex

    Joined:
    Jul 6, 2012
    Posts:
    154
    try changing .ActivityMain to com.testing.myproject.ActivityMain inside your manifest. I had a similar problem (where main activity was not found) and that solved it.

    Also how can you tell that is has found the package.
     
  5. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    I assume this because I put on Manifest ".ActivityMain", and the error log show the activity name inside the package com.testing.myproject, which is correct.

    Also I tried to change to com.testing.myproject.ActivityMain on Manifest but I've the same problem.
     
  6. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    Well.. solved after delete entirely this package and create a new one with different name, strange but works now
     
  7. Hemaolle

    Hemaolle

    Joined:
    Jun 25, 2013
    Posts:
    10
    I had a similar error message when I tried to place my plugin .jar file under a subdirectory in the Plugins/Android directory, i.e. Plugins/Android/<MyPlugin>/<myplugin>.jar. The problem was solved by placing the par directly in the root of the Android plugins directory, i.e. Plugins/Android/<myplugin>.jar.

    Edit: Should mention also, that I removed the separate AndroidManifest.xml file the plugin was using. In my case all the options there were already the same as in another AndroidManifest.xml file we had directly under the Plugins/Android directory. So that might have had some effect too, but I think I tried to remove the manifest already earlier and just that didn't seem to help.
     
    Last edited: Nov 22, 2016
    mmmistercrow and ramioooz like this.