0

I've written a piece of vanilla Java code to do a specific task. It contains a bunch of packages and resource files.

I want to import the vanilla Java project to Android to use some of its utilities.

I've tried to build my project to jar file, add it to the libs/ folder and import it. I've also tried to import it directly to the project dependencies. However, none of the above worked. The jar file showed up in the "External Library" part, but I cannot import it from a class inside as it gave me compilation error.

Hoàng Tùng
  • 100
  • 1
  • 2
  • 10

1 Answers1

0

HERE you have plenty of ways how to attach jar to Android project

are you shure that your jar (assuming properly built) will work on Android? not all components and classes of "vanilla" Java are available on Googles OS... check out THIS topic for more info

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Can you specify more about the "properly built" part? :) My Java project is made for String handling, taking in a string and outputing a string. Pure Java, no external library is used. – Hoàng Tùng Dec 09 '20 at 10:52
  • I'm not familiar with creating `jar` files, just assumed you've built this file properly :) Android isn't "pure Java", not every class available in Java is also available in Android (it have own set of packages). you can't use `jar`s which are using not-available-in-android - e.g. Swing isn't available on Android, it delivers own classes for building UI) – snachmsm Dec 09 '20 at 11:01
  • you could also built your `jar` with newest version of Java, which isn't supported by Android (some info about supporting version 8 in [HERE](https://developer.android.com/studio/write/java8-support), more info about newer versions of Java support in [HERE](https://jakewharton.com/androids-java-9-10-11-and-12-support/)) – snachmsm Dec 09 '20 at 11:02
  • besides all above: note that Android have own virtual machine (Dalvik/ART), which isn't fully compatible with standard one (common Java) – snachmsm Dec 09 '20 at 11:04