javax.* cannot be imported in my Android app?

Those classes are not included in the Android library. You have to use the Android specific sounds APIs. See: http://developer.android.com/reference/android/media/package-summary.html


I had the same problem. I've resolved it by downloading sources of OpenJDK (for example, from here: http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/classes/javax/sound ) and exporting the required package into *.jar file to include that file into android app. It worked just fine for me.


Be aware that when you run an Android app: you don't run/compile it on a standard JVM/JDK, you don't even execute java bytecode. Google choose the java language (or at least a subset of it) as the language to do Android development, but it's only the language.

At the end the compiled java code is not java bytecode, but this is dalvik bytecode. (there is no .class files, but .dex files)

So, when doing Android development: you cannot use the full JavaSE API: you are limited to the API supported by the dalvik VM (available here).

(Note that when you browse this API beware of the version in the top right corner of the page : Added in API level X. It informs you about the Android-API version supporting that class or method)


If you download OpenJDK from the Red Hat Developer Program (free membership), you can find the .java source files for the entire OpenJDK including javax.sound.sampled. I was able to debug my Android app using OpenJDK8.

Please note, not all OpenJDK8 features are available in Android yet so only include the classes you need. For more information, see https://developer.android.com/studio/write/java8-support.html