question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{name}_nativedeps.so is not built

See original GitHub issue

{name}_nativedeps.so is not built for java_binary / java_test targets, whether launcher attribute is set or not.

Description of the problem / feature request / question:

Without nativedeps library it becomes difficult to load all the (transitively) required libraries at once.

If possible, provide a minimal example to reproduce the problem:

BUILD

package(default_visibility = ["//visibility:public"])

licenses(["notice"])  # MIT

genrule(
    name = "copy_link_jni_header",
    srcs = ["@openjdk_linux//:jni_h"],
    outs = ["jni/jni.h"],
    cmd = "cp -f $< $@",
)

genrule(
    name = "copy_link_jni_md_header",
    srcs = ["@openjdk_linux//:jni_md_h"],
    outs = ["jni/jni_md.h"],
    cmd = "cp -f $< $@",
)

cc_library(
    name = "jni_inc",
    hdrs = [":jni/jni.h", ":jni/jni_md.h"],
    includes = ["jni"],
)

cc_library(
    name = "jni",
    srcs = ["xxx_jni.cc"],
    deps = ["//:jni_inc"],
    alwayslink = 1,
)

java_library(
    name = "xxx",
    srcs = ["Xxx.java"],
    deps = [":jni"],
)

java_library(
    name = "xxx_tests",
    srcs = ["XxxTest.java"],
    deps = [
        ":xxx",
        "@junit_junit//jar",
    ],
    testonly = 1,
)

java_test(
    name = "XxxTest",
    test_class = "org.xxx.XxxTest",
    runtime_deps = [":xxx_tests"],
)

WORKSPACE

# Description:
#   Bazel workspace file for xxx.

workspace(name = "org_xxx")

maven_jar(
    name = "junit_junit",
    artifact = "junit:junit:4.12",
)

new_http_archive(
    name = "openjdk_linux",
    url = "https://bazel-mirror.storage.googleapis.com/openjdk/azul-zulu-8.20.0.5-jdk8.0.121/zulu8.20.0.5-jdk8.0.121-linux_x64.tar.gz",
    sha256 = "7fdfb17d890406470b2303d749d3138e7f353749e67a0a22f542e1ab3e482745",
    build_file_content = """
package(
    default_visibility = ["//visibility:public"],
)
filegroup(
    name = "jni_h",
    srcs = ["zulu8.20.0.5-jdk8.0.121-linux_x64/include/jni.h"],
)
filegroup(
    name = "jni_md_h",
    srcs = ["zulu8.20.0.5-jdk8.0.121-linux_x64/include/linux/jni_md.h"],
)""",
)

Xxx.java

package org.xxx;

class Xxx {
  static native int doXxx();
}

XxxTest.java

package org.xxx;

import static org.junit.Assert.fail;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class XxxTest {

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

  @Test
  public void testXxx() {
    if (Xxx.doXxx() != 42) {
      fail("Nevermind");
    }
  }
}

xxx_jni.cc

#include <jni.h>

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jint JNICALL
Java_org_xxx_Xxx_doXxx(JNIEnv* env, jobject /*jobj*/) {
  return 42;
}

#ifdef __cplusplus
}
#endif

Environment info

  • Operating System: Ubuntu

  • Bazel version (output of bazel info release): release 0.5.0

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
eustascommented, May 31, 2017

What I see:

  • JavaBinary has no intention to create ‘combined’ library; so documentation should be fixed (or, better, implementation should be upgraded)
  • java.library.path is set to a directory that should contain symlinks to native dependency libraries; unfortunately this directory is not created

Going to take a look at android targets implementation, to see how native dependencies are processed there…

0reactions
eustascommented, Oct 13, 2017

With some voodoo-rituals and a grain of luck I’ve managed to have working JNI builds for windows… (see https://github.com/google/brotli/pull/612/files)

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Android packages are ignored when using VCPKG with ...
The following packages will be built and installed: openssl[core]:x86-windows -> 1.1.1n ... is not found on source ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found