Unexpected e_machine: 3 in KaliumJNI for Android

I am trying to use the crypto libsodium library (NaCl portable version (nacl.cr.yp.to)) on Android, but I cannot figure out how to properly compile / use Kalium-JNI binding .

So far, I have successfully compiled libsodium as described on the libsodium website. In addition, I used a new script compiler added 3 days ago. As a test, I compiled the version of android-x86, and also compared the file sizes of the resulting library files. They are different from each other, so it seems that they work. As a next step, I installed KaliumJNI using the newly created android libsodium files. There are no problems.

In my small android-maven-test application, which is basically the "Hello World" archetype, I'm just trying to create a new key pair:

import org.abstractj.kalium.keys.KeyPair;
KeyPair Alice = new KeyPair();

IntelliJ successfully compiled my small program, but when I try to run it on an emulator (or on my Nexus S), it will work. At first it crashed because it could not find the kaliumjni library, so I added libtestjni.so (which is the .so library created by KaliumJNI) for my project properties that fixed this problem. The following error message I received told me that libtestjni.so is not 32bit (I have 64-bit Ubuntu 12.04LTS). I don’t understand why this should be 32 bits, but in any case I managed to create a 32-bit Ubuntu 12.04LTS VM and a compiled version of libsodium and KaliumJNI to create a 32-bit libtestjni.so file. But when I use this 32-bit file in my original application (on my 64-bit computer), I get the following error:

java.lang.IllegalStateException: Could not execute method of the activity
    at android.view.View$1.onClick(View.java:3823)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at android.view.View$1.onClick(View.java:3818)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/IM.CRYPTO-1/libtestjni.so" has unexpected e_machine: 3
    at java.lang.Runtime.loadLibrary(Runtime.java:364)
    at java.lang.System.loadLibrary(System.java:526)
    at org.abstractj.kalium.NaCl.<clinit>(NaCl.java:36)
    at org.abstractj.kalium.keys.KeyPair.<init>(KeyPair.java:36)
    at IM.CRYPTO.HelloAndroidActivity.buttonClick(HelloAndroidActivity.java:43)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at android.view.View$1.onClick(View.java:3818)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)

, , , . , e_machine: 3 - , , . Android 4.0 (Android API 14), API 14 ( Nexus CM Android 4.3.1). , libsodium .

:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>IM.CRYPTO</groupId>
<artifactId>cryptolibAndroid</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>cryptolibAndroid</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <platform.version> 4.0.1.2
        </platform.version>
    <android.plugin.version>3.6.0</android.plugin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>${platform.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.abstractj.kalium</groupId>
        <artifactId>kalium-jni</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

</dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>${android.plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                    <attachJar>true</attachJar>
                </configuration>

            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
                <sdk>
                    <platform>14</platform>
                </sdk>
            </configuration>
        </plugin>
    </plugins>
</build>

NaCl.java

( testjni (KaliumJNI))

package org.abstractj.kalium;


public class NaCl {

    public static Sodium sodium() {
        return SingletonHolder.SODIUM_INSTANCE;
    }

    private static final String LIBRARY_NAME = "sodium";

    private static final class SingletonHolder {
        public static final Sodium SODIUM_INSTANCE = new Sodium();
    }

    private NaCl() {
    }

    static {
        System.loadLibrary("testjni");
    }
}

, .

, JAVA, libsodium + Kalium (NOT KaliumJNI) .

+3
1

: (.so-file) Intel x86, ( ), , ( ARM). , :

: java.lang.UnsatisfiedLinkError: dlopen : "/data/app-lib/IM.CRYPTO-1/libtestjni.so" e_machine: 3

? Android NDK Makefile ( Android.mk) . , Linux ( ) , , , Android-.

+1

All Articles