Android Unity plugin - java

I want to use unity android plugin in my AR application. The app has an AR camera, an image target and a 3d object.
ON ECLIPSE :
I create a default android application on eclipse. I click build automatically and check project name -> proeprties -> isLibrary. I create a class named Bridge on eclipse project.
Bridge.java
package com.tutorial.pluginforunity;
public class Bridge {
public static int ReturnInt() {
return 5;
}
}
ON UNITY :
I create a BridgeForUnity.cs file. Conent of it :
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
public class BridgeForAndroid : MonoBehaviour {
#if UNITY_ANDROID
//&& !UNITY_EDITOR
public static int ReturnInt () {
AndroidJavaClass ajc = new AndroidJavaClass("com.tutorial.pluginforunity.Bridge");
return ajc.CallStatic<int>("ReturnInt") ;
}
#endif
void Start () {
}
void Update () {
}
}
I edit DefaultTrackableEventHandler.cs that attached to image target.
private void Update() {
#if UNITY_ANDROID
GUI.Label(new Rect(10, 10, 100, 20), "Return = " + BridgeForAndroid.ReturnInt());
#endif
if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); }
}
I copy jar file under bin folder in eclipse project. I paste it under Assets/Plugins/Android.When I run this application, I see only black screen.

To see the return value from a plugin, move the code to OnGUI from Update.

Related

(Android Unity plugin) i created a simple plugin, expected 123, got 0

I'm trying to make a plugin for Unity, but not even the simplest class works.
In Android Studio I created a library module, and in it, the following class:
package com.vuforia.android.pluginlib;
import static android.os.Looper.getMainLooper;
public class Multi {
static public Multi mult=new Multi();
static public int testes =123;
}
After that I added to the gradle of lib, the following configurations of a Task,to create the aar:
task copyPlugin (type : Copy){
dependsOn assemble
from ('build/outputs/aar')
into ('../../Assets/Plugins/Android')
include(project.name+'-release.aar')
}
In unity, I created some sprite, and added such script to it:
using UnityEngine;
public class movetest : MonoBehaviour
{
private AndroidJavaClass javaClass = null;
void Update()
{
javaClass = new AndroidJavaClass("com.vuforia.android.pluginlib.Multi");
int i = javaClass.GetStatic<int>("testes");
Debug.Log("->>"+i);
}
}
and when clicking on run, then what is received "- >>0".
I assume you are running in the editor because you stated "when clicking on run"..
Java plugins will not work in the editor. You would need to deploy to an Android device to test the functionality.

Suddenly error ObjectSetting.java file after importing existing project on eclipse

I'm making a Auto SMS sender app on android,
Last time my app is working fine, but suddenly I've to delete the project form my eclipse, for this I wanna again import this project,
After importing this project my app is not working, showing lots of error on Object file.
Please check the screenshot http://prntscr.com/75v2cg
Here is my code
package com.example.serviceexample.model.object;
import java.io.Serializable;
public class ObjectSetting extends Object implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int setting_id;
private String setting_name;
private String setting_value;
public int getSetting_id() {
return setting_id;
}
public void setSetting_id(int setting_id) {
this.setting_id = setting_id;
}
public String getSetting_name() {
return setting_name;
}
public void setSetting_name(String setting_name) {
this.setting_name = setting_name;
}
public String getSetting_value() {
return setting_value;
}
public void setSetting_value(String setting_value) {
this.setting_value = setting_value;
}
public ObjectSetting() {
this.setting_id = 0;
this.setting_name = "";
this.setting_value = "";
}
public ObjectSetting(String name, String value) {
this.setting_id = 0;
this.setting_name = name;
this.setting_value = value;
}
public ObjectSetting(int id, String name, String value) {
this.setting_id = id;
this.setting_name = name;
this.setting_value = value;
}
}
Try setting the java build path . Installed jre needs to be reset in eclipse project properties. As you can see its showing error for java.io and String Class itself .
Frist of all Check your Eclipse preferences. window -> preferences -> Java -> Installed JREs . The installed Jre you're using should be marked there. Also check your project's build path: Right click on the project -> Properties -> Java Build Path. then check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one from an installed JDK (Alternate Jre).

Xamarin java binding library compiler error

I have a android application (Java) that uses an Android Library.
Everything works fine, but I need to wrap this application into a Xamarin application. So I decided to transform this application into a 2nd Android Library.
I created my Xamarin Android application, and an Android Java Bindings Library project in which I added the two .aar files to the "Jars" folder.
The problems come when I try to compile this binding project. I get a lot of errors like this one :
/.../obj/Release/generated/src/Com.Google.Common.Util.Concurrent.ForwardingListenableFuture.cs(17,17): Error CS0102: The type `Com.Google.Common.Util.Concurrent.ForwardingListenableFutureInvoker' already contains a definition for `id_delegate' (CS0102)
When I open the generated ForwardingListenableFuture.cs file there's this code :
[global::Android.Runtime.Register ("com/google/common/util/concurrent/ForwardingListenableFuture", DoNotGenerateAcw=true)]
internal partial class ForwardingListenableFutureInvoker : ForwardingListenableFuture, global::Com.Google.Common.Util.Concurrent.IListenableFuture {
public ForwardingListenableFutureInvoker (IntPtr handle, JniHandleOwnership transfer) : base (handle, transfer) {}
protected override global::System.Type ThresholdType {
get { return typeof (ForwardingListenableFutureInvoker); }
}
static IntPtr id_delegate;
// Metadata.xml XPath method reference: path="/api/package[#name='com.google.common.util.concurrent']/class[#name='ForwardingListenableFuture']/method[#name='delegate' and count(parameter)=0]"
[Register ("delegate", "()Lcom/google/common/util/concurrent/ListenableFuture;", "GetDelegateHandler")]
protected override global::Com.Google.Common.Util.Concurrent.IListenableFuture Delegate ()
{
if (id_delegate == IntPtr.Zero)
id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Lcom/google/common/util/concurrent/ListenableFuture;");
return global::Java.Lang.Object.GetObject<global::Com.Google.Common.Util.Concurrent.IListenableFuture> (JNIEnv.CallObjectMethod (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
}
static IntPtr id_delegate;
// Metadata.xml XPath method reference: path="/api/package[#name='com.google.common.util.concurrent']/class[#name='ForwardingFuture']/method[#name='delegate' and count(parameter)=0]"
[Register ("delegate", "()Ljava/util/concurrent/Future;", "GetDelegateHandler")]
protected override global::Java.Util.Concurrent.IFuture Delegate ()
{
if (id_delegate == IntPtr.Zero)
id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Ljava/util/concurrent/Future;");
return global::Java.Lang.Object.GetObject<global::Java.Util.Concurrent.IFuture> (JNIEnv.CallObjectMethod (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
}
static IntPtr id_delegate;
// Metadata.xml XPath method reference: path="/api/package[#name='com.google.common.collect']/class[#name='ForwardingObject']/method[#name='delegate' and count(parameter)=0]"
[Register ("delegate", "()Ljava/lang/Object;", "GetDelegateHandler")]
protected override global::Java.Lang.Object Delegate ()
{
if (id_delegate == IntPtr.Zero)
id_delegate = JNIEnv.GetMethodID (class_ref, "delegate", "()Ljava/lang/Object;");
return global::Java.Lang.Object.GetObject<global::Java.Lang.Object> (JNIEnv.CallObjectMethod (Handle, id_delegate), JniHandleOwnership.TransferLocalRef);
}
}
Indeed, the "id_delegate" is duplicated..
I also have warnings like this related to the 1st .aar (not the application one) :
/../JARTOXML: Warning J2X9001: Couldn't load class com/company/project/controllers/activities/MenuActivity : java.lang.NoClassDefFoundError: android/support/v4/app/FragmentActivity (J2X9001)
OK I solved the first part of the errors by adding remove-node statements to the Metadata.xml.
For the 2nd part, adding a reference to Xamarin.Android.Support.v4 solved the problem.

Issue Exporting .app Using Processing and Leap Motion SDK

I have been trying to export a standalone application for Mac using the "Export Application" function in Processing. The simple application, which involves updating a float value on the screen that corresponds to the y-axis position of a hand detected by a Leap Motion, works perfectly well within Processing. However, once I export the application and try to run it, the app opens for a brief second and quickly closes. I have exported applications from Processing successfully before, but not one that uses the Leap SDK. I am using the LeapMotion library for Processing to access the Leap SDK: https://github.com/heuermh/leap-motion-processing. Here is my code:
import processing.core.*;
import com.leapmotion.leap.processing.*;
import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Listener;
public class Test extends PApplet {
Controller controller;
MyListener listener;
float position = 0.0f;
class MyListener extends Listener {
public void onFrame(Controller controller) {
if (!controller.frame().hands().isEmpty()) {
position = controller.frame().hands().leftmost().palmPosition().get(1);
}
}
}
public void setup() {
size(600,600);
controller = new Controller();
listener = new MyListener();
controller.addListener(listener);
}
public void draw() {
background(0);
textAlign(CENTER,CENTER);
textSize(50);
text(position, 300,300);
}
public static void main(String args[]) {
PApplet.main("Test");
}
}
When I export the application, the contents of the application are as follows:
Info.plist
Java
-core.jar
-gluegen-rt-natives-macosx-universal.jar
-gluegen-rt.jar
-jogl-all-natives-macosx-universal.jar
-jogl-all.jar
-LeapJava.jar
-LeapMotion.jar
-libLeap.dylib
-libLeapJava.dylib
-Test.jar
MacOS
-Test
Plugins
-jdk1.7.0_45.jdk
Resources
-en.lproj
-sketch.icns
PkgInfo
Any help would be greatly appreciated!
P.S. I've already tried bundling the program into a runnable JAR file.

Phonegap: Object xx has no method 'exec' at file:///android_asset/www/cordova.js

I developed a tiny module in Android. When using the debug- or run method in Eclipse to test the app on my "real" device, everything works flawlessly.
Using Eclipse (Kepler), PhoneGap 3.1 and Android API 10
But when I sign, export, install and run the app, I see the following error in the debugger once the plugin is called:
file:///android_asset/www/cordova.js: Line 863 : Uncaught TypeError:
Object org.apache.cordova.al#41ae5438 has no method 'exec'
Uncaught TypeError: Object org.apache.cordova.al#41ae2400 has no
method 'exec' at file:///android_asset/www/cordova.js
I am waiting for the deviceready with a deferred object:
var def_deviceready = $.Deferred();
document.addEventListener("deviceready", deviceready, false);
function deviceready(){
def_deviceready.resolve();
}
function dbaccess(query, arg, callback) {
var dbaccess = cordova.require("cordova/plugin/dbaccess");
$.when(def_deviceready).done(dbaccess.getData(query, arg, callback));
};
dbaccess.js:
cordova.define("cordova/plugin/dbaccess", function (require, exports, module) {
var exec = require("cordova/exec");
module.exports = {
getData: function (query, arg, callback) {
exec(callback, function(){ callback('callbackerror')}, "DBAccess", query, arg);
}
};
});
DBAccess.java:
public class DBAccess extends CordovaPlugin {
HashMap<String, SQLiteDatabase> dbmap;
/**
* Constructor.
*/
public DBAccess() {
dbmap = new HashMap<String, SQLiteDatabase>();
}
#Override
public boolean execute(String action, String arg, CallbackContext callbackContext) throws JSONException {
Log.v("info", "This is what we got here: action=\'" + action +"\', arg=\'"+ arg +"\'.");
if (action != null) {
String Result = getData(action, arg);
this.echo(Result, callbackContext);
return true;
}
return false;
}
.....
.....
...and also the config.xml contains:
<feature name="DBAccess">
<param name="android-package" value="com.phonegap.plugin.dbAccess.DBAccess"/>
</feature>
Any help is greatly appreciated...
your script is not able to include dbaccess.js try to add it forcefully in head tag. thats why its not able to exec the method
I checked the whole project again, thanks to the comment of Vicky (I had the dbaccess.js included...).
I found that for some reason, AppLaud configured my App to run with PhoneGap 3.0, but it was being exported with 2.9, and a different config.xml - hence the inclusion for my module wasn't there at all. I could not figure out where or how the different version/xml file was configured/located in.
So I ended up creating a whole new project, copied my relevant files into the according folders, and now I am up and running!

Categories