Simple question about Android libs setup

I am trying to setup an environment to use for example the AndroidSensorJoyInput class.
It uses Androids specific I know, so I need to add the android.jar probally, but how to add the correct libs ?
I tried to add the sdk jar and it gets error on the compiling, and the android.jar from the mobile project dosent seens to be the right one…
Any tips ?

You do that in the android part of the project (the mobile folder), no need to add any libraries to the main project. See here:

1 Like

Its not clear for me yet, I have an class called AndroidSensorJoyInput, should I delete and add it to the mobile project ? Will my app able to access that class that way ?

Yes, read the last paragraph of that link again.

I think you referring to this part :

“Then in the android part of the code you make a connection to the camera and update the image in the AppState. This also allows you to easily support cameras on other platforms in the same way or fallback to something else in case the platform doesn’t support a camera.”

But when I put the class in the mobile project, it seens its not able to read jm3 classes… What am I doing wrong ?

First lines :

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Vibrator;
import android.view.Surface;
import android.view.View;
import com.jme3.input.AbstractJoystick;
import com.jme3.input.DefaultJoystickAxis;
import com.jme3.input.InputManager;
import com.jme3.input.JoyInput;
import com.jme3.input.Joystick;
import com.jme3.input.JoystickAxis;
import com.jme3.input.SensorJoystickAxis;
import com.jme3.input.RawInputListener;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.math.FastMath;
import com.jme3.util.IntMap;
import com.jme3.util.IntMap.Entry;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

When in jm3 project, its not able to see android.* classes, when in mobile its not able to see com.jme3.* …

It does, just build the project.

Its failing on the android compilation :

1 error; aborting
C:\projects\java\jm3_games\AntMaze3D\nbproject\mobile-impl.xml:10: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:888: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:890: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:902: The following error occurred while executing this line:
C:\Program Files (x86)\Android\android-sdk\tools\ant\build.xml:283: null returned: 1
BUILD FAILED (total time: 3 seconds)

No idea, thats in the android sdk build file.

Thats odd, I remove and recreated the project, now it compiles, but I cant instantiate the AndroidSensorJoyInput on the project…

This is how I add it , I dont know if I did it right :

You can only instantiate it on the Android side, on the main project side you’d have a generic class that gets its info from the Android class. Again, read that last paragraph.

Ok, I still dont understand. If the class from mobile are not available to the main project, do it means I should build all classes in the mobile ? When you say that the generic class “gets its from the android class”, it looks like it suppose to work that way ( the way in the picture ) , but its not working for me, maybe some problem in my environment ?

The mobile project has the classes of the main project. The main project doesn’t have the classes from the mobile project. So if an android event arrives the android class captures it and sends it to the main project class which itself doesn’t have android specific code. Then you for example on iOS just make that android class an iOS class and send the data to the same main project class.

So how this works ? How the android class will send data to the main class, or how the main class can capture this data ? It just means I cant just do AndroidSensorJoyInput x; in the main class then… I fell that this information is missing in the docs, I read and read again and there is nothing there on how to do it.

Look at the “Communication Between your Application & Main Activity” part.

That was what I was looking for ! Thanks loopies !

You welcome… it’s a selfish move on my part… I gain some goodwill that I later spend asking questions :D.

You don’t even need an interface for this… I don’t get whats so unclear about that

class AndroidSpecific{
  JmeMainClass notAndroid;
  public getEvent(Event evt){

I didnt notice the second document thats all… An link to this document on the last paragraph would make it clear.
For who is reading this for the first time,the first doc makes you think its automatic…

What I just wrote as pseudo code is described on the page I linked.