Extending UnityPlayerActivity (Class not found exception)

Hi guys, I can’t find what am I doing wrong for a long time.

I’ve read this tutorial (Unity - Manual: Create and use plug-ins in Android) and I try to extend UnityPlayerActivity.

I’m doing this with this Java Code (from example):

package com.company.product;

import com.unity3d.player.UnityPlayerActivity;

import android.os.Bundle;
import android.util.Log;

public class OverrideExample extends UnityPlayerActivity {

    protected void onCreate(Bundle savedInstanceState) {

        // call UnityPlayerActivity.onCreate()
        super.onCreate(savedInstanceState);

        // print debug message to logcat
        Log.d("OverrideActivity", "onCreate called!");
    }

    public void onBackPressed()
    {
        // instead of calling UnityPlayerActivity.onBackPressed() we just ignore the back button event
        // super.onBackPressed();
    }
}

which I’m using to do jar with this:

javac OverrideExample.java -bootclasspath c:\adt-bundle-windows-x86_64-20130729\adt-bundle-windows-x86_64-20130729\sdk\platforms\android-18\android.jar -classpath d:\tools\Unity\Editor\Data\PlaybackEngines\androidplayer\bin\classes.jar -d .
jar cf OverrideExample.jar com

then I add this jar into /Assets/Plugins/Android

and add this AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.product">
  <application android:icon="@drawable/app_icon" android:label="@string/app_name">
	<activity android:name=".OverrideExample"
			  android:label="@string/app_name"
			  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        <intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="android.intent.category.LAUNCHER" />
		</intent-filter>
	</activity>
  </application>
</manifest>

And when I’m trying to run it on device, I’m get this error:

10-17 15:35:06.434: E/AndroidRuntime(5926): FATAL EXCEPTION: main
10-17 15:35:06.434: E/AndroidRuntime(5926): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.product/com.company.product.OverrideExample}: java.lang.ClassNotFoundException: com.company.product.OverrideExample in loader dalvik.system.PathClassLoader[/data/app/com.company.product-1.apk]
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.os.Looper.loop(Looper.java:130)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread.main(ActivityThread.java:3691)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at java.lang.reflect.Method.invoke(Method.java:507)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at dalvik.system.NativeStart.main(Native Method)
10-17 15:35:06.434: E/AndroidRuntime(5926): Caused by: java.lang.ClassNotFoundException: com.company.product.OverrideExample in loader dalvik.system.PathClassLoader[/data/app/com.company.product-1.apk]
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
10-17 15:35:06.434: E/AndroidRuntime(5926): 	... 11 more

I’ve set bungle identifier to com.company.product, I’ve done jar with package folders, I’ve done and checked all the mistakes that I’ve found on internet… but still can’t go over this error, please help, guys!

here is ZIP with my project: http://goo.gl/v6f8qe

MORE on this problem:

When I build my project I’ve got this warning:

I’ve decided to unpack apk, and see what there is inside *.dex files and there is no my classes at all.
So Issue no in this: unity doesn’t include my classes!

You are probably not using Eclipse if you’re building the jar from command line, but if you were using Eclispe I’d sugest you to check if you marked your project as a Library Project.

Most likely you are compiling your classes with java 7. The google dex tool will silently drop any classes that are not Java 6 compliant. Try specifying -source 1.6 and -target 1.6 for the java compiler.