0

I'm new in ReactNative, and I want to import a Java class into my ReactNative project. Is that possible? How should I do that?

The Java class includes using of Java BigInteger:

public java.math.BigInteger randomPrimeBigInteger(int bitlen, int certainty, java.util.Random rng) {

       return new java.math.BigInteger(bitlen, certainty, rng);
}
Hassan Shahbazi
  • 1,543
  • 9
  • 26
  • 1
    [Why applets in JDK 9 are deprecated?](https://stackoverflow.com/questions/45535112/why-applets-in-jdk-9-are-deprecated); [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web); [Oracle's finally killing its terrible Java browser plugin](https://www.theverge.com/2016/1/28/10858250/oracle-java-plugin-deprecation-jdk-9) – MadProgrammer Dec 03 '17 at 08:18
  • @MadProgrammer What is the alternative solution? – Hassan Shahbazi Dec 03 '17 at 08:20
  • Otter then a pure HTML/css solution, java web start would be the next closet solution – MadProgrammer Dec 03 '17 at 08:24
  • @MadProgrammer I am working on a `ReactNative` project. They can't be used within my project at the moment. – Hassan Shahbazi Dec 03 '17 at 08:26
  • 1
    Then you’re out of choices – MadProgrammer Dec 03 '17 at 08:47
  • You can use this Java class in react-native (but only for Android), by adding it in the native side and exposing it as a JS function. See [Native Modules](https://facebook.github.io/react-native/docs/native-modules-android.html). – Kraylog Dec 03 '17 at 08:58
  • @NimrodArgov I know the `Native Modules`, but I want it to be accessible for the iOS project as well. I am looking for a cross-platform way – Hassan Shahbazi Dec 03 '17 at 09:00
  • Have you checked out [JS alternatives](http://mikemcl.github.io/bignumber.js/)? – Kraylog Dec 03 '17 at 09:05
  • @NimrodArgov I had checked some of them before I asked this question, but I want to have all native methods of Java `Big Integer` such as `bitLength` or `bitCount`. They lack some of these methods – Hassan Shahbazi Dec 03 '17 at 09:13

1 Answers1

0

You can write this Java code at the Android's end and call this method from your JS side after creating a wrapper which can communicate to/fro native side.

not_dying
  • 161
  • 5
  • Actually, we need to use Java code on both `iOS` and `Android` projects. Supplementary, we want it to be synchronized, while `Native Module` working in the asynchronized mode. – Hassan Shahbazi Dec 05 '17 at 13:46