twystd / tweetnacl-android

TweetNaCl crypto library port to Android
Other
5 stars 2 forks source link

Cannot build in my own project #1

Closed varunagarwal315 closed 1 year ago

varunagarwal315 commented 7 years ago

I have coped the code from native-lib , the TweetNacl code and the exceptions as well. The gradle syncs well. Now If I try to call the functions in another activity, I get this error

        try {
            KeyPair keyPair = TweetNaCl.cryptoBoxKeyPair();
            byte[] val =keyPair.publicKey;
            LogD(bytesToHex(val));
        } catch (KeyPairException e) {
            e.printStackTrace();
        }

First issue is that to use cryptoBoxKeyPair(), the function in the TweetNacl.java file had to be made static. Now If I run this I get an error that points to this line and throws the exception java.lang.UnsatisfiedLinkError.

    /**
     * Loads the TweetNaCl JNI library.
     * 
     */
    static {
        System.loadLibrary("tweetnacl");
    }

If I comment out this line this error comes

java.lang.UnsatisfiedLinkError: No implementation found for int com.example.varun.vesica.encryption.TweetNaCl.jniCryptoBoxKeyPair(byte[]

In Usage section of the ReadMe.md I am following this line Alternatively, copy the libs and src directories to your own project. but not able to do it. Could someone tell me how to tackle these errors. Thanks

twystd commented 7 years ago

Native JNI functions are bound to a package (in this case za.co.twyst.tweetnacl) when the native library is compiled, so you can't move the Java class to a different package without updating the 'C' implementation and recompiling the library. Ditto with changing a function to static - you need to update the JNI signature.

Suggestion: put the TweetNaCl java class back into it's original package and get it working like that. Once you have a working reference implementation you can make a version of the native lib with your own package name (if you feel strongly about it :-))

dheerajrajjak commented 7 years ago

@varunagarwal315 did you figure it out? I am trying to port tweetnacl for android.

twystd commented 1 year ago

Closing - no response and no activity