Android的工作室1.3 RC1 NDK无法加载本地库
今晚我打开我的NDK应用与全新的Android 1.3工作室preVIEW工作。我有2个装置的Nexus 5(5.1.1)和MotoG(4.4.4)。当通过编译NDK,建立两个设备上应用程序的工作。使用gradle这个打造的Nexus 5执行正确,但在MotoG我得到一个异常:
Tonight I switched my ndk application to work with the new Android Studio 1.3 preview. I have 2 devices Nexus 5(5.1.1) and MotoG(4.4.4). When compiled via ndk-build the application works on both devices. Using gradle build the Nexus 5 executes correctly but on the MotoG I get an 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 to start activity ComponentInfo{com.mbyan.android/com.mbyan.android.GL2JNIActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.mbyan.android-1/libgl2jni.so
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app-lib/com.mbyan.android-1/libgl2jni.so
at android.app.NativeActivity.onCreate(NativeActivity.java:183)
at com.mbyan.android.GL2JNIActivity.onCreate(GL2JNIActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:111)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
本的build.gradle如下:
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"
}
// You can modify the NDK configuration for 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'
}
演播室1.3的build.gradle看起来比&LT不同,1.3的变化中概述:
Studio 1.3 build.gradle looks different than <1.3 the changes are outlined in:
http://tools.android.com/tech-文件/新建的系统/ gradle这个实验性
工作Android.mk:
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)
和Application.mk:
And Application.mk:
APP_ABI := all
APP_STL := gnustl_static
APP_PLATFORM := android-14
另外,你会注意到在LOCAL_STATIC_LIBRARIES列出的依赖性: android_native_app_glue
。我抄android_native_app_glue.c / android_native_app_glue.h的项目,因为我还没有找到一种方法来链接依赖库。
Also you will note the dependency outlined in LOCAL_STATIC_LIBRARIES: android_native_app_glue
. I have copied android_native_app_glue.c/android_native_app_glue.h to the project because I have not found a way to link dependant libraries.
顺便说一句,我使用它自动从AndroidManifest活动的元数据加载本地共享库的NativeActivity的。
BTW I am using the NativeActivity which automatically loads the native shared library from the AndroidManifest Activity Metadata.
AndroidManifest.xml中:
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 anyone had a similar issue?
我觉得你的问题来自于一个事实,即目前由NDK集成选择的APP_PLATFORM不正确。
I think your issue comes from the fact that the APP_PLATFORM currently selected by the ndk integration is incorrect.
我报这个错误早些时候在这里:的https: //$c$c.google.com/p/android/issues/detail?id=177530
I've reported this bug earlier here: https://code.google.com/p/android/issues/detail?id=177530