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
0
Question by pirou · Apr 27, 2016 at 03:19 PM · androidunity 5pluginaugmented-realitylogcat

Unity+ARToolkit embedded in AndroidStudio Help

Hi everyone, i am working on a project right now and i hope to find some help here. i saw lots of stuff regarding these topics separately but not working together and they helped me for previous dev but not for this one.

The goal is to use augmented reality with Unity3D + ARToolKit in native android using Android Studio. First, i started by exporting unity projects into AndroidStudio. Thanks to updates on AndroidStudio, it is now quite easy. Right now i am able to:

  • Run directly the Unity view by running the UnityPlayerActivity in Android Studio,

  • Run the app with a first activity, say the MainActivity, and i can launch the unity activity by clicking on a button.

  • Run unity with both previous cases and by adding a framelayout on the unity view, i can interact in realtime with the unity view and change a gui text depending of which button i click on. The button are all native android and are sending string messages to unity which i can get thanks a c# script and as a consequence, changing the Gui text in unity.

  • Run unity by converting an unity project imported as an android studio project and converted as an android library (.aar). So basically, i have one project with my main activities and one project with the unity features. I converted the android studio project with unity features as .aar library and imported this library into my main project. i can launch unity from my main project by calling the library activity.

This is all working so if someone is interested in one of this features, i can help them.

Here is my problem: I want to add some AR. I am using an AR plugin in unity called ARToolKit. It's not as robust as vuforia but it's working. I followed the same method as for the other features and completed my unity project with AR. In unity, it's working. I then exported it as a google android project and imported the created directory into Android Studio so i have my android studio project with unity+AR features. I let the gradle build and if i launch the default activity on my phone, i can load my AR scene in unity and play with the AR so it's great.

The problem is the following: i want to add an activity, say MainActivity and launch it first, i will see my first view and by clicking on the button, i could launch unity+AR. Unfortunately, when i do that, the app crash and i don't know why. I already did that with unity only, without the ar plugin and it worked fine so why doesn't it work now??

As i said, the app is working if i launch the default activity, the UnityARPlayerActivity but crashes if i try to run another activity first.

I think it may be due to some manifest problems. For the AR to work when running, it may need to access some hardwares or permissions or other stuff and by trying to launch another activity, it crashes because of some exceptions not catch.

i am using unity Unity 5.3.4f1 (64-bit), Android Studio 2.0 i started two weeks ago so i have recent SDK and Jre.


update: one of the problem i found looking at the logcat was “java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity”, i found other answers and fix it by replacing “public class MainActivity extends AppCompatActivity” by “public class MainActivity extends Activity”

So basically, to launch my AR scene, i am using this intent from my MainActivity. « Intent intent = new Intent(MainActivity.this, UnityARPlayerActivity.class); »

Right now i am able to launch unity + AR directly on my smartphone and I don't really understand what i did to make it work but i succeeded in launching the MainActivity first and then unity+AR thanks to a button. I don't really get how but it is working

new problems are: launching the main activity and then unity+AR is working on my phone (sony xperiaZ C6603) API 22 et android 5.1.1) but only mine, it doesn't work on my colleague's tablet (samsung SM-T550, android 5.0.2 and API 21), it doesn't work on emulators using genymotion and i tried for different APIs and Android versions. The logcat is showing the following error :

Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ludo.AR/org.artoolkit.ar.unity.UnityARPlayerActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0

MainActivity:

 package com.ludo.AR;
 
 import android.app.Activity;
 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 
 import org.artoolkit.ar.unity.UnityARPlayerActivity;
 
 public class MainActivity extends Activity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
         Button button = (Button) findViewById(R.id.button);
         button.setOnClickListener(new View.OnClickListener() {
 
             @Override
             public void onClick(View v) {
                 goToSecondActivity();
             }
         });
     }
 
     private void goToSecondActivity() {
         Intent intent = new Intent(MainActivity.this, UnityARPlayerActivity.class);
         startActivity(intent);
     }
 }



Logcat:

 04-27 17:01:23.028 25322-25322/com.ludo.AR E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: com.ludo.AR, PID: 25322
                                                              java.lang.Error: FATAL EXCEPTION [main]
                                                              Unity version     : 5.3.4f1
                                                              Device model      : samsung SM-T550
                                                              Device fingerprint: samsung/gt510wifixx/gt510wifi:5.0.2/LRX22G/T550XXU1AOJ1:user/release-keys
                                                              
                                                              Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ludo.AR/org.artoolkit.ar.unity.UnityARPlayerActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
                                                                  at android.app.ActivityThread.access$900(ActivityThread.java:181)
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                  at android.os.Looper.loop(Looper.java:145)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:6117)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                               Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                                  at android.content.res.Resources.getValue(Resources.java:2358)
                                                                  at android.content.res.Resources.loadXmlResourceParser(Resources.java:3958)
                                                                  at android.content.res.Resources.getXml(Resources.java:2223)
                                                                  at android.preference.GenericInflater.inflate(GenericInflater.java:261)
                                                                  at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:272)
                                                                  at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:485)
                                                                  at android.preference.PreferenceManager.setDefaultValues(PreferenceManager.java:444)
                                                                  at org.artoolkit.ar.unity.UnityARPlayerActivity.onCreate(UnityARPlayerActivity.java:118)
                                                                  at android.app.Activity.performCreate(Activity.java:6374)
                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855) 
                                                                  at android.app.ActivityThread.access$900(ActivityThread.java:181) 
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                  at android.os.Looper.loop(Looper.java:145) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:6117) 
                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                  at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 


manifest code:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.ludo.AR"
     android:installLocation="preferExternal"
     android:versionCode="1"
     android:versionName="1.0">
 
     <uses-sdk
         android:minSdkVersion="15"
         android:targetSdkVersion="23" />
 
     <uses-permission android:name="android.permission.CAMERA" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
     <uses-feature
         android:name="android.hardware.camera.any"
 
         android:required="false" />
     <uses-feature
         android:name="android.software.leanback"
         android:required="false" />
     <uses-feature
         android:name="android.hardware.camera"
         android:required="false" />
     <uses-feature
         android:name="android.hardware.camera.autofocus"
         android:required="false" />
     <uses-feature android:glEsVersion="0x00020000" />
     <uses-feature
         android:name="android.hardware.touchscreen"
         android:required="false" />
     <uses-feature
         android:name="android.hardware.touchscreen.multitouch"
         android:required="false" />
     <uses-feature
         android:name="android.hardware.touchscreen.multitouch.distinct"
         android:required="false" />
 
     <application
         android:banner="@drawable/app_banner"
 
         android:icon="@drawable/app_icon"
         android:isGame="true"
         android:label="@string/app_name">
         <activity
             android:name="org.artoolkit.ar.unity.UnityARPlayerActivity"
             android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
             android:label="@string/app_name"
             android:screenOrientation="portrait">
 
 
             <meta-data
                 android:name="unityplayer.ForwardNativeEventsToDalvik"
                 android:value="true" />
         </activity>
         <activity android:name="org.artoolkit.ar.base.camera.CameraPreferencesActivity"></activity>
         <activity android:name=".MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
             </intent-filter>
         </activity>
     </application>
 
 </manifest>

Sorry if this is long, i try to explain clearly everything and it's my first time posting questions here

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
1
Best Answer

Answer by pirou · May 20, 2016 at 09:56 AM

i am posting a reply myself as i found a solution. it seems there is a bug when exporting to android and a library is not compiled so you need to add it manually in your android studio project.

Check this link to understand how to do it. http://www.artoolkit.org/community/forums/viewtopic.php?f=26&t=9625

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 Nireas · Oct 17, 2018 at 11:16 AM

@pirou Can you please repost the answer since i have the exact same problem and i am keeping getting a black camera screen.. Thanks in advance.,@pirou The link is broken can you please post somewhere the answer since i have the same exactly problem.

Comment
Add comment · Show 3 · 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 pirou · Oct 17, 2018 at 11:35 AM 0
Share

Hi, i contacted artoolkit devs as a last resort and i believe they told me to add the resource/library manually in the android studio project to fix it.

The problem is just that the resource/library is in the unity project but not after exporting and it causes the error. you should try to add to add it manually to your export.

avatar image Escarlatum · Oct 03, 2019 at 04:22 PM 0
Share

Hi there @pirou, I'm having a similar error here and I couldn't understand what you just said about the resource/library, can you explain to me how I do that?

$$anonymous$$y problem is I can't run my app in the android, and the error in the logcat is similar to yours...

avatar image pirou · Oct 04, 2019 at 06:44 AM 0
Share

Hi @Escarlatum, it's been a very long time but from what i remember, i needed to export my unity project into an android studio one to use the video camera of the phone. During the export, there were errors and after a long time, i asked the artoolkit devs who said it was a bug and unity resources folder didn't export properly during the export. They told me to add the missing resources manually. If you are in the same state, you need to compare your unity projet assets Resourcesfolder with the ones of your android studio export and if some of the resources are missing, add them manually. Good luck

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Android plugin problem build CommandInvokationFailure 2 Answers

Failed to re-package resources after adding unity in-app purchase service 1 Answer

Android plug-in for Unity3D 0 Answers

Object appearing in the wrong location in stereo mode when using Google VR sdk? 0 Answers

'Failed to create agent' error made even after building the NavMesh in real time - AR Foundation 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