Running native code in OnCreate() Method - Android

Hi guys, so I’m trying to integrate Amazon Ads SDK into my Unity project for Android. I feel like I’m missing something basic. When I export my Unity project to an Android Project, I can launch and run my application just fine. However, any code that I put into the OnCreate() method of NPUnityPlayerActivity does not get called. Even leaving all the code as is and adding a simple Log.V() message doesn’t get printed.

When I create a brand new Android project, I can call code in the OnCreate() method and get the Amazon Ads to show no problem. What am I missing? It’s like the NPUnityPlayerActivity is not actually getting run, but the application runs so it has to be.

I haven’t done much coding with the ADT so any help would be appreciated. Thanks!

Where in your project are you placing your custom activity?

Have you read the docs here: Unity - Manual: Create and use plug-ins in Android

Basically, you need to place your custom compiled java code under Plugins/Android, or, in case of an Android library project, place it under Plugins/Android/ProjName.

The project should be compiled to a .jar (will be looked for under Plugins/Android/ProjName/bin or libs).

Also, in case you implement your own activity, you must:

  1. Derive it from UnityPlayerActivity (not from Activity)
  2. Provide your custom AndroidManifest.xml, so Unity will know which custom activity it should use for the exported APk.