Native Android App project calls untiy exported Android project

Source: Internet
Author: User
Tags google vr

Background: Use Google VR SDK for Unity to develop 3D scene features, then export Android items and merge them into one Android app for other activity calls.

  • The main activity for the Android project, developed by the Google VR for Unity SDK Untiy project, is com.google.unity.GoogleUnityActivity. If you need to extend some functionality on this basis, you need to implement your own activity (for example, named Googlecardboardactivity), and inherit the com.google.unity.GoogleUnityActivity, and modify the main activity inside the androidmanifest.xml to the activity that you have implemented (like the googlecardboardactivity you just created).
  • If you replace the main activity with unityplayeractivity, when you call the untiy scene, the content does not see the cardboard UI (the Back button, the split line in the middle, and the Set button).
  • the code for calling Googleunityactivity from Android activity is as follows:
     1  Intent Googleunityintent = new  Intent (this , Googleunityactivity. class   2  androidactivity. this  .startactivity (googleunityintent);  3  androidactivity. this . Finish (); 

    If the activity is custom, replace the Googleunityactivity.class with a custom activity.class.

  • method called Googleunityactivity defined in the unity scene:
     1  androidjavaclass JC = new  androidjavaclass ( " com.unity3d.player.unityplayer   "  2  androidjavaobject jo = JC. Getstatic<androidjavaobject> ( "  CurrentActivity    3  Jo. Call ( " someandroidmethod  " ); 
    The

    Someandroidmethod is the Android method written in Googleunityactivity.

  • If you need to call Munityplayer in the Android method, you'll need to write the code that calls Munityplayer in the Android UI thread, or you'll get an error:

     1  public       void   Someandroidmethod () { 2  Runonuithread (new   Runnable () { 3   @Override  4  public  void   run () { 5   m Unityplayer.quit ();  6  }  7  });  8 } 
  • Couldn ' t find "libgvrunity.so"
    androidruntime:fatal EXCEPTION:mainProcess:com.elfnaga.googlecardboard, PID:6401java.lang.unsatisfiedlinkerror:dalvik.system.pathclassloader[dexpathlist[[zip File"/data/app/com.elfnaga.googlecardboard-1/base.apk"],nativelibrarydirectories=[/data/app/com.elfnaga.googlecardboard-1/lib/arm64,/data/app/com.elfnaga.googlecardboard-1/Base. apk!/lib/arm64-v8a,/vendor/lib64,/system/lib64]] couldn't find "libgvrunity.so"At Java.lang.Runtime.loadLibrary (Runtime.java:367) at Java.lang.System.loadLibrary (System.java:1076) at com.google.unity.GoogleUnityActivity.<clinit> (Googleunityactivity.java: -) at Java.lang.Class.newInstance (Native Method) at android.app.Instrumentation.newActivity (instrumentation . Java:1068) at Android.app.ActivityThread.performLaunchActivity (Activitythread.java:2374) at Android.app.ActivityThread.handleLaunchActivity (Activitythread.java:2535) at android.app.activitythread.access$1100(Activitythread.java:154) at Android.app.activitythread$h.handlemessage (Activitythread.java:1396) at Android.os.Handler.dispatchMessage (Handler.java:102) at Android.os.Looper.loop (Looper.java:148) at Android.app.ActivityThread.main (Activitythread.java:5582) at Java.lang.reflect.Method.invoke (Native Method) at com.android.Internal. os. Zygoteinit$methodandargscaller.run (Zygoteinit.java:726) at com.android.Internal. os. Zygoteinit.main (Zygoteinit.java:616) A- on Ten: -:38.089 13512-14679/? W/activitymanager:force Finishing Activity Com.elfnaga.googlecardboard/com.google.unity.googleunityactivity

    The reason is that libgvrunity.so in the Google VR SDK for unity only increased the version armv7 and x86 and did not provide arm64 versions, so you need to modify the Build.gradle in your Android project to add product preferences:

    1 Android {2 productflavors {3 ARMv7 {4 NDK {5Abifilter"armeabi-v7a"6             }7         }8 x86 {9 NDK {TenAbifilter"x86" One             } A         } - Fat -     } the}

    The libgvrunity.so will not appear to be found.

Native Android App project calls untiy exported Android project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.