Log in or register to post comments

Same Unity project works in Editor and on iOS, but no camera on Android

August 14, 2017 - 2:04pm #1

So, the app works great in the Editor and on iOS, but no camera on Android.  Here are my versions:

Unity: 5.3.4f1

Vuforia SDK: v6.2.10

Android SDK: 25.0.3

JDK: 8u144

Device: HTC Sense 6.0 with Android 4.4.4

 

AndroidManifest.xml settings for SDK and camera:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />

<uses-feature android:name="android.hardware.camera" />

<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.CAMERA" />

 

Unity Project Settings:

Graphics APIs: OpenGLES2 & OpenGLES3

Min API Level: Android 4.1 (API Level 16)

Mono2x, ARMv7, External Install, External SDCard

No stripping level.



Here is an error I'm seeing on start from LogCat.  I have not found this to be coming from any of our custom Android/Unity plugin calls.

08-14 16:36:35.822: I/Unity(20506): AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='forName' signature='(Ljava/lang/String;)Ljava/lang/Object;' in class Ljava/lang/Class;

08-14 16:36:35.822: I/Unity(20506): java.lang.NoSuchMethodError: no static method with name='forName' signature='(Ljava/lang/String;)Ljava/lang/Object;' in class Ljava/lang/Class;

08-14 16:36:35.822: I/Unity(20506):  at com.unity3d.player.UnityPlayer.nativeRender(Native Method)

08-14 16:36:35.822: I/Unity(20506):  at com.unity3d.player.UnityPlayer.a(Unknown Source)

08-14 16:36:35.822: I/Unity(20506):  at com.unity3d.player.UnityPlayer$b.run(Unknown Source)

08-14 16:36:35.822: I/Unity(20506):   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0

08-14 16:36:35.822: I/Unity(20506):   at UnityEngine.AndroidJNISafe.GetStaticMethodID (IntPtr clazz, System.String name, System.String sig) [0x00000] in <filename unknown>:0

08-14 16:36:35.822: I/Unity(20506):   at UnityEngine._AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.String signature, Boolean isStatic) [0x00000] in <filename unknown>:0

08-14 16:36:35.822: I/Unity(20506):   at UnityEngine.AndroidJNIHelper.GetMethodID (IntPtr javaClass, System.String methodName, System.String signature, Boolean isStatic) [0x00000] in <f

Then right after the error, Vuforia says is has initialized, but the CameraDevice.Instance.IsActive() is false.

I made a copy of the project and built with Unity 5.5.2 to see if it was our Unity version with Vuforia 6.2, but same thing, no camera.



Is this a permissions thing?  I've completely deleted the app and reinstalled and received zero prompts for permissions that was added in Android 6.0 (API level 23).



Any help?

Same Unity project works in Editor and on iOS, but no camera on Android

August 17, 2017 - 11:10am #3

The sample app runs great and our manifest is pretty much a match. I was finally able to fix the problem in our app and its working great now.  It was a combination of several issues, that once we fixed one, another one would appeared.  I'm adding as much info here as possible, even though unrelated to Vuforia, might be helpful for others, as this took several days to figure out and fix.

 

  • "Vuforia cannot be started before it is initialized. Please disable Delayed Initialization in the Vuforia configuration or initialize Vuforia manually with the VuforiaRuntime-class" - Weird because we have delayed initialization unchecked and we had zero vuforia API calls until it returns from the "RegisterVuforiaStartedCallback" callback. We were able to fix this by creating an empty initialize scene, like in the examples and wait a second to allow Vuforia to setup.
  • "Unable to convert classes into dex format" - We fixed this one by removing any duplicate jar/aar plugins in project.  Also was seeing this error if the Android plugin manifests had the same package name as our Unity project.  And seeing this error because we are using Unity 5.3.4 and the "BuildConfig.class" in our *.aar.  Also needed mark the "libs/classes.jar" as provided.  Here is what we added to our gradle scripts for those issues:



    task removeBuildConfig(dependsOn: "compileReleaseSources") {

        doFirst {

            file("$buildDir/intermediates/classes/release/pathToFile/BuildConfig.class").delete()

        }

    }

    dependencies {

        provided fileTree(dir: 'libs', include: ['*.jar'])

    }

In the end, once all of these were fixed, the original "java.lang.NoSuchMethodError: no static method with name..." error was related to incorrectly calling our android plugins from Unity.  You need to make sure you use the full class namespace path:



new AndroidJavaObject("com.company.app.AndroidClassName");

I hope that this helps someone else. ;)

 

Same Unity project works in Editor and on iOS, but no camera on Android

August 15, 2017 - 5:02pm #2

Hello xpensv,

Are you seeing this same behavior when running the sample app on Android? If not, could you compare your AndroidManifest to the version in the sample and see if you are missing anything?

Thanks,

-Vuforia Support

Log in or register to post comments