Package android.hardware does not exist

I’m using JMP to try and build an android game. I’ve got a working demo that compiles and runs on my android device just fine. Now I’m working on adding accelerometer support.



In the class I’ve written to read in accelerometer values, the build process cannot find the android classes unless I manually add android.jar to “Libraries”.



However, if I manually add “android.jar” to the libraries, then when I try to build I get the following



[java]


Handling Resources...
Generating resource IDs...
Compiling 2 source files to /home/josh/Codes/java/forestrunner/mobile/bin/classes
Converting compiled files and external libraries into /home/josh/Codes/java/forestrunner/mobile/bin/classes.dex...

trouble processing "java/nio/CharBuffer.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

..

1 error; aborting
/home/josh/Codes/java/forestrunner/nbproject/mobile-impl.xml:21: The following error occurred while executing this line:
/home/josh/android_sdk/android-sdk-linux/tools/ant/build.xml:752: The following error occurred while executing this line:
/home/josh/android_sdk/android-sdk-linux/tools/ant/build.xml:754: The following error occurred while executing this line:
/home/josh/android_sdk/android-sdk-linux/tools/ant/build.xml:766: The following error occurred while executing this line:
/home/josh/android_sdk/android-sdk-linux/tools/ant/build.xml:256: null returned: 1
[/java]

If I comment out all the android stuff from my accelerometer class I can remove android.jar from the list of libraries and the game will build and run fine.

It's my understanding that by enabling android development under "Application->mobile" in project properties, the "android.jar" should be automatically added. However, this does not seem to be the case.

Any help would be appreciated.

You do android stuff in the android sub-project, read the manual.

Thanks. I’ve read that page several times over. I guess I missed this tidbit:


Since the main project is not configured to access the android api directly, you have to install NBAndroid (see above) to be able to edit the created android project in the SDK. After installing, click the "open project" button and navigate to the "mobile" folder inside the main project folder (it should show up with an android "a" icon) and open it.

Well technically you don’t need NBAndroid, it just makes the editing of the files easier with code completion etc. :slight_smile: The android sub-project is a normal android project and can be edited in any compatible environment really. So if you can code android classes off the top of your head then you just need to stick them in the “mobile/src” folder.