Bazel: Android Example Runtime Failure No Implementation Found

Created on 9 Mar 2020  路  2Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Running the example Android App fails at runtime.

Feature requests: what underlying problem are you trying to solve with this feature?

Trying to run the example Android project.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Set Android SDK locations to:

android_sdk_repository(
name = "androidsdk",
api_level = 29,
build_tools_version = "29.0.2",
path = "/usr/local/share/android-sdk",
)

android_ndk_repository(
name = "androidndk",
api_level = 21,
path = "/usr/local/share/android-ndk",
)

then build:

bazel build //examples/android/java/bazel:hello_world

install apk:

adb install ~/Downloads/__staging/hello_world.apk

What operating system are you running Bazel on?

Android 10 (Pixel 2XL)

What's the output of bazel info release?

release 2.2.0

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

https://github.com/bazelbuild/bazel.git
94619102201b5e5f092042c190eba730df0ca00a
94619102201b5e5f092042c190eba730df0ca00a

Any other information, logs, or outputs that you want to share?

2020-03-09 10:54:54.102 19986-19986/bazel.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: bazel.android, PID: 19986
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String bazel.Jni.hello() (tried Java_bazel_Jni_hello and Java_bazel_Jni_hello__)
at bazel.Jni.hello(Native Method)
at bazel.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

team-Android untriaged

Most helpful comment

Turns out the cc_library rules require alwayslink = True to be set.

cc_library(
name = "jni",
srcs = ["jni.cc"],
deps = [":jni_dep"],
alwayslink = True,
)

cc_library(
name = "jni_dep",
srcs = ["jni_dep.cc"],
hdrs = ["jni_dep.h"],
alwayslink = True,
)

All 2 comments

Do you set the targetSdkVersion to 29 in your AndroidManifest?

Turns out the cc_library rules require alwayslink = True to be set.

cc_library(
name = "jni",
srcs = ["jni.cc"],
deps = [":jni_dep"],
alwayslink = True,
)

cc_library(
name = "jni_dep",
srcs = ["jni_dep.cc"],
hdrs = ["jni_dep.h"],
alwayslink = True,
)

Was this page helpful?
0 / 5 - 0 ratings