0

Not all Java Packages are part of Android but is there a way to gain access to them through some work around? Purely as an example javax.sound is one such class. Yes Android has classes to do the same thing but if we already had the working Java written, rewriting it all using Android APIs is not ideal.

Is there any way to use the Java API or do we have to use the Android API?

user6363994
  • 21
  • 1
  • 2
  • It depends on *which* Java API you are talking about. Some have been ported, others haven't. – Stephen C Apr 11 '17 at 07:45
  • Basically, I believe the short answer is no. The Java APIs define an interface. Every virtual machine implementation is then responsible for implementing the API, and the Android virtual machines (ART and Dalvik) do not implement those parts of the API. The reason why these would be hard to implement yourself is that such functionality usually has to be implemented in native code (C++,C,etc.) to get any kind of reasonable performance. The alternative would be to make a wrapper around the built in Android functionality that acts in the same way as the javax functions. – bremen_matt Apr 11 '17 at 07:45
  • However, I am assuming that is impossible or extremely difficult. Otherwise, I would imagine that Google would have implemented it. – bremen_matt Apr 11 '17 at 07:48
  • @bremen_matt Counterexample: I believe RMI hasn't been provided, but there is no native code in that. – user207421 Apr 11 '17 at 08:01

2 Answers2

1

No, not all Java libraries have been ported to Android. You will need to use the Android-specific implementation, especially for things that deal with the hardware layer or require a specific technology stack, such as audio libraries.

AndroidGuy
  • 52
  • 7
0

Yep totally you can but it depending on which libs that you want to use for example you cant use databases drivers in your android apps, neither UI libs , but you can use gson for example

Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34