Android Studio 1.3 RC1 NDK Unable to load native library -
tonight switched ndk application work new android studio 1.3 preview. have 2 devices nexus 5(5.1.1) , motog(4.4.4). when compiled via ndk-build application works on both devices. using gradle build nexus 5 executes correctly on motog exception:
07-11 04:13:58.509 16751-16751/com.mbyan.android e/androidruntime﹕ fatal exception: main process: com.mbyan.android, pid: 16751 java.lang.runtimeexception: unable start activity componentinfo{com.mbyan.android/com.mbyan.android.gl2jniactivity}: java.lang.illegalargumentexception: unable load native library: /data/app-lib/com.mbyan.android-1/libgl2jni.so @ android.app.activitythread.performlaunchactivity(activitythread.java:2198) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2257) @ android.app.activitythread.access$800(activitythread.java:139) @ android.app.activitythread$h.handlemessage(activitythread.java:1210) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5086) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: java.lang.illegalargumentexception: unable load native library: /data/app-lib/com.mbyan.android-1/libgl2jni.so @ android.app.nativeactivity.oncreate(nativeactivity.java:183) @ com.mbyan.android.gl2jniactivity.oncreate(gl2jniactivity.java:40) @ android.app.activity.performcreate(activity.java:5248) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:111) @ android.app.activitythread.performlaunchactivity(activitythread.java:2162)
the build.gradle looks like:
apply plugin: 'com.android.model.application' model { android { compilesdkversion = 21 buildtoolsversion = "22.0.1" defaultconfig.with { applicationid = "com.mbyan.android" minsdkversion.apilevel = 14 targetsdkversion.apilevel = 14 versioncode = 1 versionname = "1.0" } compileoptions.with { sourcecompatibility javaversion.version_1_6 targetcompatibility javaversion.version_1_6 } } android.ndk { modulename = "gl2jni" stl = "stlport_static" ldlibs += "log" ldlibs += "android" ldlibs += "egl" ldlibs += "glesv2" string includebasepath = "-i${projectdir}/src/main/jni/engine/include" string includebaseglm = "-i${projectdir}/src/main/jni/engine/glm" string includebaselua = "-i${projectdir}/src/main/jni/engine/lua" string includeappglue = "-i${projectdir}/src/main/jni/android_app_glue" cflags += includebaseglm cflags += includebasepath cflags += includebaselua cflags += includeappglue cflags += "-dgl_v_2" cflags += "-duse_android" cppflags += includebaseglm cppflags += includebasepath cppflags += includebaselua cppflags += includeappglue cppflags += "-dgl_v_2" cppflags += "-duse_android" } // can modify ndk configuration each variant. components.android { binaries.aftereach { binary -> binary.mergedndkconfig.cppflags.add( "-dvariant=\"" + binary.name + "\"") } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' }
studio 1.3 build.gradle looks different <1.3 changes outlined in:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental
the working android.mk:
local_path:= $(call my-dir) include $(clear_vars) local_module := gl2jni local_cflags := -dgl_v_2 -duse_android -i$(local_path)/engine/include -i $(local_path)/engine/glm -i $(local_path)/engine/lua file_list := $(wildcard $(local_path)/**/*.cpp) file_list += $(wildcard $(local_path)/*.cpp) file_list += $(wildcard $(local_path)/engine/lua/*.c) file_list += $(wildcard $(local_path)/*.c) local_src_files := $(file_list:$(local_path)/%=%) local_static_libraries := android_native_app_glue local_ldlibs := -llog -lglesv2 -landroid -legl include $(build_shared_library) $(call import-module, native_app_glue)
and application.mk:
app_abi := app_stl := gnustl_static app_platform := android-14
also note dependency outlined in local_static_libraries: android_native_app_glue
. have copied android_native_app_glue.c/android_native_app_glue.h project because have not found way link dependant libraries.
btw using nativeactivity automatically loads native shared library androidmanifest activity metadata.
androidmanifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mbyan.android" > <application android:label="@string/gl2jni_activity" android:hascode="true" android:icon="@drawable/ic_launcher"> <activity android:name=".gl2jniactivity" android:theme="@android:style/theme.notitlebar.fullscreen" android:launchmode="singletask" android:screenorientation="landscape" android:configchanges="orientation|keyboardhidden"> <meta-data android:name="android.app.lib_name" android:value="gl2jni" /> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> <uses-feature android:glesversion="0x00020000" android:required="true"/> <uses-sdk android:minsdkversion="14"/> </manifest>
has had similar issue?
i think issue comes fact app_platform selected ndk integration incorrect.
i've reported bug earlier here: https://code.google.com/p/android/issues/detail?id=177530
Comments
Post a Comment