android - Build NativeActivity using ndk-build -
i trying launch native activity after launching java(i need load library that's why launching nativeactivity java).
how build sample using android.mk? original sample uses gradle. tried build , @ launch library fails load.
fatal exception: main process: sample.simple.com.myapplication, pid: 14917 java.lang.runtimeexception: unable start activity componentinfo{sample.simple.com.myapplication/android.app.nativeactivity}: java.lang.illegalargumentexception: unable load native library: /data/app/sample.simple.com.myapplication/lib/arm64/libnactivity.so
here snippets of code.
android.mk made following http://brian.io/android-ndk-r10c-docs/programmers_guide/html/md_2__samples_sample--nativeactivity.html
local_path := $(call my-dir) include $(clear_vars) local_module := nactivity local_src_files := main.c local_ldlibs := -llog -landroid -legl -lglesv1_cm local_static_libraries := android_native_app_glue include $(build_shared_library) $(call import-module,android/native_app_glue)
java activity
public class dummyactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.loadlibrary("nactivity"); intent intent = new intent(dummyactivity.this, android.app.nativeactivity.class); dummyactivity.this.startactivity(intent); // setcontentview(r.layout.activity_dummy); } }
android manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="display.rendering.simple.com.myapplication"> <application android:label="@string/app_name" android:hascode="true"> <activity android:name="dummyactivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="android.app.nativeactivity"> <meta-data android:name="android.app.lib_name" android:value="nactivity" /> </activity> </application> </manifest>
build.gradle
ndk{ modulename ="nactivity" } sourcesets.main { jni.srcdirs = [] jni.srcdir "src/main/libs" }
thanks
your build.gradle disables built-in call ndk-build here:
jni.srcdirs = []
this means no native library being built. no library -> no library matching name on device -> loadlibrary error.
you don't need use android.mk file launch native-activity java. other ndk samples document how build , use native code build.gradle. build.gradle file hello-jni great place start.
i advise against using android.mk unless have to, there ndk samples using android.mk if need them.
Comments
Post a Comment