Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by swarooppal · Apr 20, 2017 at 09:19 AM · androidpluginandroidplugin

Starting a activity in Android Library

I had an existing Android Studio Project with one Activity Class and lots of other Java classes. I converted that to a library project by changing the apply plugin: 'com.android.application' to apply plugin: 'com.android.library' in the build.gradle(Module: app) file.

The generated .aar file was imported to Unity. I am able to call the functions in the normal java classes in the plugin but unable to start the activity in the plugin. This is how I am trying to access the MainActivity class AndroidJavaClass myAndroidClass = new AndroidJavaClass("com.companyName.appname.MainActivity");

I have changed the Manifest in the plugin to specify exact path for the class com.companyName.appname.MainActivity

This always fails with AndroidJavaException: java.lang.ClassNotFoundException: com.companyName.appname.MainActivity for the MainActivity class but works fine for the regular java classes in the plugin.

I also found that there are ways to start the same by extending activity as UnityPlayerActivity in the Android studio code but wanted some direction before diving into that as I am unable to figure out why Unity can find the regular java classes but not the MainActivity?

Can anyone please suggest how to resolve this? My end goal is to convert the Android Studio project to a library and to start the activity from Unity.

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 liortal · Apr 25, 2017 at 05:24 AM 0
Share

You should make sure that: 1. The activity class does get included into the .aar (it's a simple zip file. unzip it and inspect the classes.jar file under it using some decompilation tool, like JD-GUI). 2. You have included other dependencies that this activity relies on (Android support library ? appcompat? other libraries) 3. The name is spelled correctly and exactly as in the manifest.

As a side note, in order to start an activity, you should call startActivity, you never call the activity's constructor like you would with other plain Java classes (Android will construct it for you).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by nipundavid · Jun 20, 2017 at 10:12 AM

Any luck ? I am stuck with same sort of issue. I am trying to invoke native permission dialog box from unity3D.

So far I have found no way to do this. Link - http://www.techotopia.com/index.php/Making_Runtime_Permission_Requests_in_Android_6.0

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 mrttson · Nov 08, 2017 at 05:31 PM

I've same issue. When i changed base class of MainActivity from AppCompatActivity to Activity, it's seem resolve the issue, but on my layout of activity contains class from facebook SDK ("com.facebook.login.widget.LoginButton"), then ClassNotFoundException occurs again. So sad ...

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Android Plugin OnCreate() function? (Unity project automatically open android peoject) 0 Answers

How do I override an Android Java class in Unity? 1 Answer

How do I make an Android plugin for unity? 0 Answers

How to pass accurate GPS location from android studio to unity? 0 Answers

Not rendering camera when using Unity as library on Android Studio 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