• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mervill · Oct 26, 2012 at 08:21 PM · androidjava

Overriding UnityPlayerActivity on Android, Class not found at launch.

So I'm following the section of This Page that describes a way to override UnityPlayerActivity with a custom class. I've followed the instructions to the letter, but when I run the application on device it crashes with a ClassNotFoundException on my derived class.

OverrideExample.java:

 package com.compnay.testproduct;
 
 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!");
     }
     
 }

I'm then compiling this with the classes.jar from Unity and an android.jar (Version 4.0, API 14, Unity is also set to use this API level). The resulting .class file is then compressed into a .jar with the structure:

OverrideExample.jar/com/company/testproduct/OverrideExample.class

and placed in ./Assets/Plugins/Android.

This Manifest file is also included:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.copmany.testproduct" android:versionName="1.0" android:versionCode="1">
   
     <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
   
     <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
     
         <activity android:name=".OverrideExample" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
     
         <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
         </activity>
     
         <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
             <meta-data android:name="android.app.lib_name" android:value="unity" />
             <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
         </activity>
     </application>
     
     <uses-feature android:glEsVersion="0x00020000" />
     <uses-sdk android:minSdkVersion="6" android:targetSdkVersion="16" />
     
 </manifest>

And the unfortunate result from logcat:

 I/ActivityManager( 1389): Start proc com.copmany.testproduct for activity com.copmany.testproduct/.OverrideExample: pid=30370 uid=10029 gids={3003, 1015}
 I/LAB126  ( 1452): StatusBarService hears intent. action: com.lab126.intent.TOP_WINDOW_CHANGED
 I/LAB126  ( 1452):  window changed
 I/LAB126  ( 1452): don't set softkey config for 'Starting...' window
 D/AndroidRuntime(30370): Shutting down VM
 W/dalvikvm(30370): threadid=1: thread exiting with uncaught exception (group=0x40015560)
 E/AndroidRuntime(30370): FATAL EXCEPTION: main
 E/AndroidRuntime(30370): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.copmany.testproduct/com.copmany.testproduct.OverrideExample}: java.lang.ClassNotFoundException: com.copmany.testproduct.OverrideExample in loader dalvik.system.PathClassLoader[/mnt/asec/com.copmany.testproduct-1/pkg.apk]

I've done some searching and there seem to be a few other people who've had my problem, but no solutions have been posted. D=

Thanks for your help! I'll post the answer if I manage to fix this problem myself.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sehathesam · May 02, 2017 at 02:21 PM

activity android:name=".OverrideExample"

must be : activity android:name="com.compnay.testproduct.OverrideExample"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by oferei · Jun 05, 2013 at 12:55 PM

I'm not sure, but I think the problem could be with your XML file. Perhaps you should remove the 2nd activity: com.unity3d.player.UnityPlayerActivity.

You don't need it because .OverrideExample is based on UnityPlayerActivity.

Perhaps you could also lose the 3rd activity: com.unity3d.player.UnityPlayerNativeActivity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityPlayerActivity vs. UnityPlayerNativeActivity 0 Answers

java android plugin worker thread ends up in Unity mainthread 1 Answer

Android plugin breaks when using receiver. 1 Answer

Call a Android Studio method from Unity 0 Answers

Android app is not building in Unity, Error “Gradle initialization failed.” 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges