Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Slobdell · Jul 09, 2014 at 01:58 AM · androidjavanative

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!

Comment
Add comment · Show 1
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 Slobdell · Jul 09, 2014 at 07:42 PM 0
Share

Sorry, hate to be that guy but "bump".

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by liortal · Jul 09, 2014 at 08:03 PM

Where in your project are you placing your custom activity?

Have you read the docs here: http://docs.unity3d.com/Manual/PluginsForAndroid.html

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.

Comment
Add comment · Show 4 · 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 Slobdell · Jul 09, 2014 at 08:29 PM 0
Share

It's not a custom activity, I was just trying to get something...anything to happen for me by placing one line of code into the NPUnityPlayerActivity.

You're saying I am required to make a jar file? What I'm trying to do is only like 10 lines of code so I was just trying to stick it into the existing activity. Guess I will make it a plugin.

avatar image liortal · Jul 09, 2014 at 08:35 PM 0
Share

Where do you have the source of the existing activity? and where did you place that file ?

Unity will not compile any java code for you. All has to be pre-compiled (e.g: Jar)

avatar image Slobdell · Jul 09, 2014 at 08:44 PM 0
Share

Ha alright it's all starting to make sense now I think. When I open the eclipse project there is an NPUnityPlayerActivity class that isn't compiled. I was under the impression I could stick code in there as that's the only activity registered in the manifest. Thinking about it now that is a really dumb way to do things because even if it worked I would have to paste that coed back in every time I generated the eclipse project. I'm going to make a jar. Thanks for your help. I know java but have never worked with android dev tools before so I'm a little lost.

avatar image liortal · Jul 09, 2014 at 09:24 PM 0
Share

Now I see. You export a project and not an apk ("Google Android project"). Adding code to the activity class should be O$$anonymous$$ then... I just tried it now and i see my Log calls from onCreate

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.

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to translate ArrayList to C# using AndroidJavaClass? 1 Answer

NoSuchMethodError calling android method 2 Answers

UnityPlayerActivity vs. UnityPlayerNativeActivity 0 Answers

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

Calling static jar function from Unity3D 0 Answers


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