Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couldn't find "libj2v8_android_armv7l.so" #70

Closed
Brian-McBride opened this issue Jun 12, 2015 · 9 comments
Closed

couldn't find "libj2v8_android_armv7l.so" #70

Brian-McBride opened this issue Jun 12, 2015 · 9 comments

Comments

@Brian-McBride
Copy link

I wanted to check out the performance of your lib in a native Android app.

I've used both:
compile 'com.eclipsesource.j2v8:j2v8_android_armv7l:2.2.1'
and placing the .jar directly into my libs folder in Android studio.

In each case, I am getting this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.appname/com.app.appname.MainActivity}: java.lang.IllegalStateException: J2V8 native library not loaded.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2712)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2777)
            at android.app.ActivityThread.access$900(ActivityThread.java:179)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5972)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
     Caused by: java.lang.IllegalStateException: J2V8 native library not loaded.
            at com.eclipsesource.v8.V8.checkNativeLibraryLoaded(V8.java:86)
            at com.eclipsesource.v8.V8.createV8Runtime(V8.java:74)
            at com.eclipsesource.v8.V8.createV8Runtime(V8.java:63)
            at com.app.appname.MainActivity.onCreate(MainActivity.java:39)
            at android.app.Activity.performCreate(Activity.java:6289)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2777)
            at android.app.ActivityThread.access$900(ActivityThread.java:179)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5972)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
     Caused by: java.lang.UnsatisfiedLinkError: Could not load J2V8 library. Reasons:
    dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.appname-2/base.apk"],nativeLibraryDirectories=[/data/app/com.app.appname-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libj2v8_android_armv7l.so"
            at com.eclipsesource.v8.LibraryLoader.loadLibrary(LibraryLoader.java:71)
            at com.eclipsesource.v8.V8.load(V8.java:49)
            at com.eclipsesource.v8.V8.createV8Runtime(V8.java:72)
            ... 15 more
@irbull
Copy link
Member

irbull commented Jun 12, 2015

On android you need to specify where to unpack the native libraries. We do something like this:
V8.createV8Runtime( activity.getApplicationInfo().dataDir );

@Brian-McBride
Copy link
Author

Oh, so it will drop the native libs there on runtime? Or is that the directory that the native runtimes need to be living already?

Update:
Moving my runtime call in my MainActivity to:
V8 runtime = V8.createV8Runtime(this.getApplicationInfo().dataDir);

Throws the same error.

Do I need to put something in the dataDir for the lib to find?

@Brian-McBride
Copy link
Author

Oh, I should mention that I'm using Android Studio. It seems as though this is the key:

nativeLibraryDirectories=[/data/app/com.app.appname-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libj2v8_android_armv7l.so"

I've tried creating my own jniLibs directory with the armeabi, armeabi-v7a, and x86 directories, placing the appropriate .so files in each. No go.

@irbull
Copy link
Member

irbull commented Jun 12, 2015

It will unpack them there. They are in the jar. If you don't specify it
will use ~/.j2v8 but this doesn't work on Android.
On Jun 12, 2015 8:41 PM, "Brian McBride" notifications@github.com wrote:

Oh, so it will drop the native libs there on runtime? Or is that the
directory that the native runtimes need to be living already?


Reply to this email directly or view it on GitHub
#70 (comment).

@Brian-McBride
Copy link
Author

Well, this is interesting. I created a jniLibs folder and put the libj2v8_android_armv7l.so in the armeabi-v7a directory. That got passed the error.

However, your example here fails:

        String dataDir = this.getApplicationInfo().dataDir;

        V8 runtime = V8.createV8Runtime( dataDir );

        int result = runtime.executeIntScript(""
                + "var hello = 'hello, ';\n"
                + "var world = 'world!';\n"
                + "hello.concat(world).length();\n");
        System.out.println(result);
        runtime.release();

Throwing this:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.appname/com.app.appname.MainActivity}: undefined:3: TypeError: number is not a function
    hello.concat(world).length();
    ^
    TypeError: number is not a function
            at <anonymous>:3:21

looks like valid JS to me. It's closer though. I think for Android Studio you'll have to bundle the .jar a little differently so that the .so ends up in the correct directory. That's my guess.

@irbull
Copy link
Member

irbull commented Jun 12, 2015

Sorry, I was trying to answer you from my phone without looking at the code. Ok, two things.

  1. Loading to a different location than the default requires the other constructor.
    V8 runtime = V8.createV8Runtime("", "/tmp");
    The one use used sets an alias for the global namespace, that's completely different.
  2. The JS you have is not actually valid. length() is not a method, but rather a property:

This works fine:

        V8 runtime = V8.createV8Runtime("", "/tmp");
        int result = runtime.executeIntegerScript(""
                + "var hello = 'hello, ';\n"
                + "var world = 'world!';\n"
                + "hello.concat(world).length;");
        System.out.println(result);
        runtime.release();

@Vacxe
Copy link

Vacxe commented Dec 7, 2015

I have the same error

Caused by: java.lang.UnsatisfiedLinkError: Could not load J2V8 library. Reasons: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ru.nitrobubbles.javascriptest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libj2v8_android_armv7l.so"

@irbull
Copy link
Member

irbull commented Dec 7, 2015

Can you try with Version 3.1.0 (just pushed it to maven central 1 hour ago). This packages the androd libs an aar, which should make loading native bits much easier.

<dependency>
  <groupId>com.eclipsesource.j2v8</groupId>
  <artifactId>j2v8</artifactId>
  <version>3.1.0</version>
  <type>aar</type>
</dependency>

The gradle dependency is as follows:

compile 'com.eclipsesource.j2v8:j2v8:3.1.0@aar'

@irbull
Copy link
Member

irbull commented Dec 10, 2015

Closing. Please re-open if this problem persists.

@irbull irbull closed this as completed Dec 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants