기본 사항은 two-libs sample from NDK부터 시작합시다. JNI 함수가 libtwolib-first
정적 라이브러리의 일부가되는 second.c
에 있는지
1 # Copyright (C) 2009 The Android Open Source Project
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 # the purpose of this sample is to demonstrate how one can
17 # generate two distinct shared libraries and have them both
18 # uploaded in
19 #
20
21 LOCAL_PATH:= $(call my-dir)
22
23 # first lib, which will be built statically
24 #
25 include $(CLEAR_VARS)
26
27 LOCAL_MODULE := libtwolib-first
28 LOCAL_SRC_FILES := first.c
29
30 include $(BUILD_STATIC_LIBRARY)
31
32 # second lib, which will depend on and include the first one
33 #
34 include $(CLEAR_VARS)
35
36 LOCAL_MODULE := libtwolib-second
37 LOCAL_SRC_FILES := second.c
38
39 LOCAL_STATIC_LIBRARIES := libtwolib-first
40
41 include $(BUILD_SHARED_LIBRARY)
주 : 여기 원래 Android.mk 파일이다.
먼저, 문제를 재현 해 보겠습니다. 당신은 정확하게이 문제를 설명
E/AndroidRuntime(4213): FATAL EXCEPTION: main
E/AndroidRuntime(4213): java.lang.UnsatisfiedLinkError: add
E/AndroidRuntime(4213): at com.example.twolibs.TwoLibs.add(Native Method)
E/AndroidRuntime(4213): at com.example.twolibs.TwoLibs.onCreate(TwoLibs.java:39)
E/AndroidRuntime(4213): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(4213): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(4213): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(4213): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(4213): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(4213): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(4213): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(4213): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(4213): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(4213): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(4213): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
E/AndroidRuntime(4213): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
E/AndroidRuntime(4213): at dalvik.system.NativeStart.main(Native Method)
:은 "사용하지 않는"Java_com_example_twolibs_TwoLibs_add "밖으로 제거"링커는 수정 된 프로젝트를 실행하면
...
27 LOCAL_MODULE := libtwolib-first
28 LOCAL_SRC_FILES := first.c second.c
...
36 LOCAL_MODULE := libtwolib-second
37 LOCAL_SRC_FILES :=
, 당신은 다음과 같은 오류가 발생합니다 : 변화는 간단하다() 항목.
지금 우리가이 문제를 해결하자
39 LOCAL_STATIC_LIBRARIES := libtwolib-first
39 LOCAL_WHOLE_STATIC_LIBRARIES := libtwolib-first
그리고 다시 샘플 작품을!
fadden - 우리 중 밀도가 높은 경우 - Android.mk 파일을 설정하는 방법에 대한 빠른 예를 게시 할 수 있습니까? (최소한 두 줄은 연결과 관련이 있습니다)? – EboMike