当前位置: 代码迷 >> Android >> 杞?細Android.mk绠?浠
  详细解决方案

杞?細Android.mk绠?浠

热度:603   发布时间:2016-04-28 04:54:59.0
杞?細Android.mk绠?浠?
Android.mk鏂囦欢鏄疓NU Makefile鐨勪竴灏忛儴鍒嗭紝瀹冪敤鏉ュ?Android绋嬪簭杩涜?缂栬瘧銆?/span>
鍥犱负鎵?鏈夌殑缂栬瘧鏂囦欢閮藉湪鍚屼竴涓?GNU MAKE 鎵ц?鐜??涓?繘琛屾墽琛岋紝鑰孉ndroid.mk涓?墍鏈夌殑鍙橀噺閮芥槸鍏ㄥ眬鐨勩?傚洜姝わ紝鎮ㄥ簲灏介噺灏戝0鏄庡彉閲忥紝涓嶈?璁や负鏌愪簺鍙橀噺鍦ㄨВ鏋愯繃绋嬩腑涓嶄細琚?畾涔夈??/span>
涓?涓狝ndroid.mk鏂囦欢鍙?互缂栬瘧澶氫釜妯″潡锛?/span>姣忎釜妯″潡灞炰笅鍒楃被鍨嬩箣涓?锛?/span>
1锛堿PK绋嬪簭
聽 涓?鑸?殑Android绋嬪簭锛岀紪璇戞墦鍖呯敓鎴恆pk鏂囦欢
2锛塉AVA搴?/strong>
聽 java绫诲簱锛岀紪璇戞墦鍖呯敓鎴恓ar鏂囦欢
3)C\C++搴旂敤绋嬪簭
聽鍙?墽琛岀殑C\C++搴旂敤绋嬪簭
4锛塁\C++闈欐?佸簱聽
缂栬瘧鐢熸垚C\C++闈欐?佸簱锛屽苟鎵撳寘鎴?a鏂囦欢
5锛塁\C++鍏变韩搴?/strong>
缂栬瘧鐢熸垚鍏变韩搴擄紙鍔ㄦ?侀摼鎺ュ簱锛夛紝骞舵墦鍖呮垚.so鏂囷紝 鏈変笖鍙?湁鍏变韩搴撴墠鑳借?瀹夎?/澶嶅埗鍒版偍鐨勫簲鐢ㄨ蒋浠讹紙APK锛夊寘涓???/div>
聽 鍙?互鍦ㄦ瘡涓?涓狝ndroid.mk file 涓?畾涔変竴涓?垨澶氫釜妯″潡锛屼綘涔熷彲浠ュ湪鍑犱釜妯″潡涓?娇鐢ㄥ悓涓?涓?/span>
婧愪唬鐮佹枃浠躲?偮?缂栬瘧绯荤粺涓轰綘澶勭悊璁稿?缁嗚妭闂??銆備緥濡傦紝浣犱笉闇?瑕佸湪浣犵殑 Android.mk 涓?垪鍑哄ご鏂囦欢鍜屼緷
璧栨枃浠躲?傜紪璇戠郴缁熷皢浼氫负浣犺嚜鍔ㄥ?鐞嗚繖浜涢棶棰樸?傝繖涔熸剰鍛崇潃锛屽湪鍗囩骇 NDK 鍚庯紝浣犲簲璇?/span>
寰楀埌鏂扮殑toolchain/platform鏀?寔锛岃?屼笖涓嶉渶瑕佹敼鍙樹綘鐨?Android.mk 鏂囦欢銆?/span>
娉ㄦ剰锛孨DK鐨凙nroid.mk璇?硶鍚屽叕寮?鍙戝竷鐨凙ndroid骞冲彴寮?婧愪唬鐮佺殑Anroid.mk璇?硶寰堟帴杩戯紝鐒惰?岀紪璇戠郴缁熷疄鐜颁粬浠?殑
鏂瑰紡鍗存槸涓嶅悓鐨勶紝杩欐槸鏁呮剰杩欐牱璁捐?鐨勶紝鍙?互璁╃▼搴忓紑鍙戜汉鍛橀噸鐢ㄥ?閮ㄥ簱鐨勬簮浠g爜鏇村?鏄撱??/div>
鍦ㄦ弿杩拌?娉曠粏鑺備箣鍓嶏紝鍜变滑鏉ョ湅涓?涓?畝鍗曠殑"hello world"鐨勪緥瀛愶紝姣斿?锛屼笅闈㈢殑鏂囦欢锛?/span>
聽sources/helloworld/helloworld.c
聽sources/helloworld/Android.mk
聽'helloworld.c'鏄?竴涓?JNI鍏变韩搴?/span>锛屽疄鐜拌繑鍥?hello world"瀛楃?涓茬殑鍘熺敓鏂规硶銆傜浉搴旂殑
Android.mk 鏂囦欢浼氳薄涓嬮潰杩欐牱锛?/span>
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= helloworld
LOCAL_SRC_FILES := helloworld.c
include $(BUILD_SHARED_LIBRARY)
聽 瑙i噴涓?涓嬪嚑琛屼唬鐮侊細
聽 LOCAL_PATH := $(call my-dir)
涓?涓狝ndroid.mk file棣栧厛蹇呴』瀹氫箟濂絃OCAL_PATH鍙橀噺銆傚畠琛ㄧず鏄?綋鍓嶆枃浠剁殑璺?緞銆?/span>
鍦ㄨ繖涓?緥瀛愪腑锛?瀹忓嚱鏁扳?榤y-dir鈥? 聽鐢辩紪璇戠郴缁熸彁渚涳紝 鐢ㄤ簬杩斿洖褰撳墠璺?緞(鍗冲寘鍚獳ndroid.mk file
鏂囦欢鐨勭洰褰?銆?/div>
include $(CLEAR_VARS)
CLEAR_VARS 鐢辩紪璇戠郴缁熸彁渚?鍙?互鍦?android 瀹夎?鐩?綍涓嬬殑/build/core/config.mk鏂囦欢鐪?/span>鍒板叾瀹氫箟锛屼负 CLEAR_VARS:=$(BUILD_SYSTEM)/clear_vars.mk)锛屾寚瀹氳?GNU MAKEFILE璇ヨ剼鏈?负浣犳竻闄よ?澶?LOCAL_XXX 鍙橀噺 ( 渚嬪? LOCAL_MODULE 锛?LOCAL_SRC_FILES 锛?/span>LOCAL_STATIC_LIBRARIES锛岀瓑绛夆??锛岄櫎 LOCAL_PATH銆傝繖鏄?繀瑕佺殑锛屽洜涓烘墍鏈夌殑缂栬瘧鏂囦欢閮藉湪鍚屼竴涓?GNU MAKE 鎵ц?鐜??涓?紝鎵?鏈夌殑鍙橀噺閮芥槸鍏ㄥ眬鐨勩??/span>鎵?浠ユ垜浠?渶瑕佸厛娓呯┖杩欎簺鍙橀噺锛圠OCAL_PATH闄ゅ?锛夈?傚張鍥犱负LOCAL_PATH鎬绘槸瑕佹眰鍦ㄦ瘡涓?ā鍧椾腑閮借?杩涜?璁剧疆锛屾墍浠ュ苟闇?瑕佹竻绌哄畠銆?/span>
鍙﹀?娉ㄦ剰锛岃?璇?彞鐨勬剰鎬濆氨鏄?妸CLEAR_VARS鍙橀噺鎵?鎸囧悜鐨勮剼鏈?枃浠跺寘鍚?繘鏉ャ??/span>
LOCAL_MODULE := helloworld
LOCAL_MODULE 鍙橀噺蹇呴』瀹氫箟锛屼互鏍囪瘑浣犲湪 Android.mk 鏂囦欢涓?弿杩扮殑姣忎釜妯″潡銆傚悕绉板繀椤绘槸鍞?竴鐨勶紝鑰屼笖涓嶅寘鍚?换浣曠┖鏍笺?傛敞鎰忕紪璇戠郴缁熶細鑷?姩浜х敓鍚堥?傜殑鍓嶇紑鍜屽悗缂?锛屾崲鍙ヨ瘽璇达紝涓?涓??鍛藉悕涓?foo'鐨勫叡浜?簱妯″潡锛屽皢浼氱敓鎴?libfoo.so'鏂囦欢銆?/span>
娉ㄦ剰锛氬?鏋滄妸搴撳懡鍚嶄负鈥榣ibhelloworld鈥欙紝缂栬瘧绯荤粺灏嗕笉浼氭坊鍔犱换浣曠殑 lib 鍓嶇紑锛屼篃浼氱敓鎴?libhelloworld.so銆?/span>
LOCAL_SRC_FILES := helloworld.c
聽 LOCAL_SRC_FILES 鍙橀噺蹇呴』鍖呭惈灏嗚?缂栬瘧鎵撳寘杩涙ā鍧椾腑鐨?C 鎴?C++婧愪唬鐮佹枃浠躲?備笉鐢?/span>
鍦ㄨ繖閲屽垪鍑哄ご鏂囦欢鍜屽寘鍚?枃浠讹紝缂栬瘧绯荤粺灏嗕細鑷?姩鎵惧嚭渚濊禆鍨嬬殑鏂囦欢锛屽綋鐒跺?浜庡寘鍚?枃浠讹紝浣犲寘鍚?椂鎸囧畾鐨勮矾寰勫簲璇ユ?纭???/span>
娉ㄦ剰锛岄粯璁ょ殑 C++婧愮爜鏂囦欢鐨勬墿灞曞悕鏄???cpp鈥?銆傛寚瀹氫竴涓?笉鍚岀殑鎵╁睍鍚嶄篃鏄?彲鑳界殑锛屽彧瑕佸畾涔?/span>LOCAL_DEFAULT_CPP_EXTENSION 鍙橀噺锛屼笉瑕佸繕璁板紑濮嬬殑灏忓渾鐐?涔熷氨鏄?畾涔変负 聽鈥?cxx鈥?鑰屼笉鏄??榗xx鈥?
include $(BUILD_SHARED_LIBRARY)
BUILD_SHARED_LIBRARY 鏄?紪璇戠郴缁熸彁渚涚殑鍙橀噺锛屾寚鍚戜竴涓?GNU Makefile 鑴氭湰(搴旇?
灏辨槸鍦?build/core 聽鐩?綍涓嬬殑 shared_library.mk) 锛屽皢鏍规嵁LOCAL_XXX绯诲垪鍙橀噺涓?殑鍊硷紝鏉ョ紪璇戠敓鎴愬叡浜?簱锛堝姩鎬侀摼鎺ュ簱锛夈??/span>
濡傛灉鎯崇敓鎴愰潤鎬佸簱锛屽垯鐢˙UILD_STATIC_LIBRARY
聽 鍦∟DK鐨剆ources/samples鐩?綍涓嬫湁鏇村?鏉備竴鐐圭殑渚嬪瓙锛屽啓鏈夋敞閲婄殑 Android.mk 鏂囦欢銆?/span>
浜屻?佽嚜瀹氫箟鍙橀噺
聽浠ヤ笅鏄?湪 Android.mk涓?緷璧栨垨瀹氫箟鐨勫彉閲忓垪琛?紝 鍙?互瀹氫箟鍏朵粬鍙橀噺涓鸿嚜宸变娇鐢?紝浣嗘槸NDK缂栬瘧绯荤粺淇濈暀涓嬪垪鍙橀噺鍚嶏細
聽-浠?LOCAL_寮?澶寸殑鍚嶅瓧锛堜緥濡?LOCAL_MODULE锛?/span>
聽-浠?PRIVATE_, NDK_ 鎴?APP_寮?澶寸殑鍚嶅瓧锛堝唴閮ㄤ娇鐢?級
聽-灏忓啓鍚嶅瓧锛堝唴閮ㄤ娇鐢?紝渚嬪?鈥榤y-dir鈥欙級
濡傛灉涓轰簡鏂逛究鍦?Android.mk 涓?畾涔夎嚜宸辩殑鍙橀噺锛屽缓璁?娇鐢?MY_鍓嶇紑锛屼竴涓?皬渚嬪瓙锛?/div>
MY_SOURCES := foo.c
ifneq ($(MY_CONFIG_BAR),)
聽MY_SOURCES += bar.c
endif
LOCAL_SRC_FILES += $(MY_SOURCES)
娉ㄦ剰锛氣??=鈥欐槸璧嬪?肩殑鎰忔?濓紱'+='鏄?拷鍔犵殑鎰忔?濓紱鈥?鈥欒〃绀哄紩鐢ㄦ煇鍙橀噺鐨勫?笺??/div>
涓夈?丟NU Make绯荤粺鍙橀噺
聽 杩欎簺 GNU Make鍙橀噺鍦ㄤ綘鐨?Android.mk 鏂囦欢瑙f瀽涔嬪墠锛屽氨鐢辩紪璇戠郴缁熷畾涔夊ソ浜嗐?傛敞鎰忓湪
鏌愪簺鎯呭喌涓嬶紝NDK鍙?兘鍒嗘瀽 Android.mk 鍑犳?锛屾瘡涓?娆℃煇浜涘彉閲忕殑瀹氫箟浼氭湁涓嶅悓銆?/span>
锛?锛塁LEAR_VARS:聽鎸囧悜涓?涓?紪璇戣剼鏈?紝鍑犱箮鎵?鏈夋湭瀹氫箟鐨?LOCAL_XXX 鍙橀噺閮藉湪"Module-description"鑺備腑鍒楀嚭銆傚繀椤诲湪寮?濮嬩竴涓?柊妯″潡涔嬪墠鍖呭惈杩欎釜鑴氭湰锛歩nclude$(CLEAR_VARS)锛岀敤浜庨噸缃?櫎LOCAL_PATH鍙橀噺澶栫殑锛屾墍鏈塋OCAL_XXX绯诲垪鍙橀噺銆?/span>
锛?锛塀UILD_SHARED_LIBRARY: 聽鎸囧悜缂栬瘧鑴氭湰锛屾牴鎹?墍鏈夌殑鍦?LOCAL_XXX 鍙橀噺鎶婂垪鍑虹殑婧愪唬鐮佹枃浠剁紪璇戞垚涓?涓?叡浜?簱銆?/span>
聽 娉ㄦ剰锛屽繀椤昏嚦灏戝湪鍖呭惈杩欎釜鏂囦欢涔嬪墠瀹氫箟 LOCAL_MODULE 鍜?LOCAL_SRC_FILES銆?/span>
锛?锛?BUILD_STATIC_LIBRARY:聽涓?涓?BUILD_SHARED_LIBRARY 鍙橀噺鐢ㄤ簬缂栬瘧涓?涓?潤鎬佸簱銆傞潤鎬佸簱涓嶄細澶嶅埗鍒扮殑APK鍖呬腑锛屼絾鏄?兘澶熺敤浜庣紪璇戝叡浜?簱銆?/span>
绀轰緥锛?/strong>include $(BUILD_STATIC_LIBRARY)
娉ㄦ剰锛岃繖灏嗕細鐢熸垚涓?涓?悕涓?span style="line-height: 28px; color: #ff6600;">lib$(LOCAL_MODULE).a鐨勬枃浠?/div>
锛?锛塗ARGET_ARCH:鐩?爣 CPU骞冲彴鐨勫悕瀛? 聽鍜?android 寮?鏀炬簮鐮佷腑鎸囧畾鐨勯偅鏍枫?傚?鏋滄槸
arm锛岃〃绀鸿?鐢熸垚 ARM 鍏煎?鐨勬寚浠わ紝涓?CPU鏋舵瀯鐨勪慨璁㈢増鏃犲叧銆?/span>
锛?锛塗ARGET_PLATFORM:Android.mk 瑙f瀽鐨勬椂鍊欙紝鐩?爣 Android 骞冲彴鐨勫悕瀛?/span>.璇︽儏鍙?弬鑰?development/ndk/docs/stable- apis.txt.
聽android-3 -> Official Android 1.5 system images
聽android-4 -> Official Android 1.6 system images
聽android-5 -> Official Android 2.0 system images
锛?锛塗ARGET_ARCH_ABI:鏆傛椂鍙?敮鎸佷袱涓?value锛宎rmeabi 鍜?armeabi-v7a銆傚湪鐜板湪鐨勭増鏈?腑涓?鑸?妸杩欎袱涓??肩畝鍗曠殑瀹氫箟涓?arm锛?閫氳繃 android 聽骞冲彴鍐呴儴瀵瑰畠閲嶅畾涔夋潵鑾峰緱鏇村ソ鐨勫尮閰嶃?傚叾浠栫殑 ABI 灏嗗湪浠ュ悗鐨?NDK 鐗堟湰涓?粙缁嶏紝瀹冧滑浼氭湁涓嶅悓鐨勫悕瀛椼?傛敞鎰忚櫧鐒舵墍鏈夊熀浜?/span>
ARM鐨凙BI閮戒細鎶?'TARGET_ARCH'瀹氫箟鎴愨?榓rm鈥欙紝 浣嗘槸浼氭湁涓嶅悓鐨勨?楾ARGET_ARCH_ABI鈥欍?偮?/span>
锛?7 锛?TARGET_ABI:鐩?爣骞冲彴鍜?ABI 鐨勭粍鍚堬紝瀹冧簨瀹炰笂琚?畾涔夋垚$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) 聽锛屽湪鎯宠?鍦ㄧ湡瀹炵殑璁惧?涓?拡瀵逛竴涓?壒鍒?殑鐩?爣绯荤粺杩涜?娴嬭瘯鏃讹紝浼氭湁鐢ㄣ?傚湪榛樿?鐨勬儏鍐典笅锛屽畠浼氭槸'android-3-arm'銆?/span>
浜斻?佹ā鍧楁弿杩板彉閲?/strong>
涓嬮潰鐨勫彉閲忕敤浜庡悜缂栬瘧绯荤粺鎻忚堪浣犵殑妯″潡銆備綘搴旇?瀹氫箟鍦?include 聽$(CLEAR_VARS)'鍜?include $(BUILD_XXXXX)'涔嬮棿銆傛?濡傚墠闈㈡弿鍐欑殑閭f牱锛?(CLEAR_VARS)鏄?竴涓?剼鏈?紝娓呴櫎鎵?鏈夎繖浜涘彉閲?/span>銆?/div>
锛?锛?LOCAL_PATH:杩欎釜鍙橀噺鐢ㄤ簬缁欏嚭褰撳墠鏂囦欢鐨勮矾寰勩?傚繀椤诲湪 Android.mk 鐨勫紑澶村畾涔夛紝鍙?互杩欐牱浣跨敤锛歀OCAL_PATH := $(call my-dir)聽 杩欎釜鍙橀噺涓嶄細琚?(CLEAR_VARS)娓呴櫎锛屽洜姝ゆ瘡涓?Android.mk 鍙?渶瑕佸畾涔変竴娆?鍗充娇鍦ㄤ竴涓?枃浠朵腑瀹氫箟浜嗗嚑涓?ā鍧楃殑鎯呭喌涓?銆?/span>
锛?锛塋OCAL_MODULE:杩欐槸妯″潡鐨勫悕瀛楋紝瀹冨繀椤绘槸鍞?竴鐨勶紝鑰屼笖涓嶈兘鍖呭惈绌烘牸銆傚繀椤诲湪鍖呭惈浠讳竴鐨?(BUILD_XXXX)鑴氭湰涔嬪墠瀹氫箟瀹冦?傛ā鍧楃殑鍚嶅瓧鍐冲畾浜嗙敓鎴愭枃浠剁殑鍚嶅瓧銆備緥濡傦紝濡傛灉涓?涓?竴涓?叡浜?簱妯″潡鐨勫悕瀛楁槸锛岄偅涔堢敓鎴愭枃浠剁殑鍚嶅瓧灏辨槸 lib.so銆備絾鏄?紝鍦ㄧ殑 NDK 鐢熸垚鏂?/span>
浠朵腑(鎴栬??Android.mk 鎴栬??Application.mk)锛屽簲璇ュ彧娑夊強(寮曠敤)鏈夋?甯稿悕瀛楃殑鍏朵粬妯″潡銆?/span>
锛?锛塋OCAL_SRC_FILES: 聽杩欐槸瑕佺紪璇戠殑婧愪唬鐮佹枃浠跺垪琛ㄣ?傚彧瑕佸垪鍑鸿?浼犻?掔粰缂栬瘧鍣ㄧ殑鏂囦欢锛屽洜涓虹紪璇戠郴缁熻嚜鍔ㄨ?绠椾緷璧栥?傛敞鎰忔簮浠g爜鏂囦欢鍚嶇О閮芥槸鐩稿?浜?LOCAL_PATH鐨勶紝浣犲彲浠ヤ娇鐢ㄨ矾寰勯儴鍒嗭紝渚嬪?锛?/span>
LOCAL_SRC_FILES := foo.c toto/bar.c\
Hello.c
聽鏂囦欢涔嬮棿鍙?互鐢ㄧ┖鏍兼垨Tab閿?繘琛屽垎鍓?鎹㈣?璇风敤"\".濡傛灉鏄?拷鍔犳簮浠g爜鏂囦欢鐨勮瘽锛岃?鐢↙OCAL_SRC_FILES +=
娉ㄦ剰锛?span style="line-height: 28px; color: #000080;">鍦ㄧ敓鎴愭枃浠朵腑閮借?浣跨敤UNIX椋庢牸鐨勬枩鏉?/).windows椋庢牸鐨勫弽鏂滄潬涓嶄細琚??纭?殑澶勭悊銆?/span>
娉ㄦ剰锛?/strong>鍙?互LOCAL_SRC_FILES := $(call all-subdir-java-files)杩欑?褰㈠紡鏉ュ寘鍚玪ocal_path鐩?綍涓嬬殑鎵?鏈塲ava鏂囦欢銆?/span>
锛?锛?LOCAL_CPP_EXTENSION:杩欐槸涓?涓?彲閫夊彉閲忥紝 鐢ㄦ潵鎸囧畾C++浠g爜鏂囦欢鐨勬墿灞曞悕锛岄粯璁ゆ槸'.cpp',浣嗘槸鍙?互鏀瑰彉瀹冿紝姣斿?锛?/span>
LOCAL_CPP_EXTENSION := .cxx
锛?锛?LOCAL_C_INCLUDES: 聽鍙??夊彉閲忥紝琛ㄧず澶存枃浠剁殑鎼滅储璺?緞銆傞粯璁ょ殑澶存枃浠剁殑鎼滅储璺?緞鏄疞OCAL_PATH鐩?綍銆?/span>
聽 绀轰緥:LOCAL_C_INCLUDES := sources/foo鎴朙OCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
LOCAL_C_INCLUDES闇?瑕佸湪浠讳綍鍖呭惈LOCAL_CFLAGS/LOCAL_CPPFLAGS鏍囧織涔嬪墠杩涜?璁剧疆銆?/span>
锛?锛塋OCAL_CFLAGS: 聽鍙??夌殑缂栬瘧鍣ㄩ?夐」锛屽湪缂栬瘧 C 浠g爜鏂囦欢鐨勬椂鍊欎娇鐢ㄣ?傝繖鍙?兘鏄?湁
鐢ㄧ殑锛屾寚瀹氫竴涓?檮鍔犵殑鍖呭惈璺?緞(鐩稿?浜嶯DK鐨勯《灞傜洰褰?锛屽畯瀹氫箟锛屾垨鑰呯紪璇戦?夐」銆?/span>
娉ㄦ剰锛?span style="line-height: 28px; color: #000080;">涓嶈?鍦?Android.mk 涓?敼鍙?optimization/debugging 绾у埆锛屽彧瑕佸湪 Application.mk 涓?寚瀹氬悎閫傜殑淇℃伅锛屽氨浼氳嚜鍔ㄥ湴涓轰綘澶勭悊杩欎釜闂??锛屽湪璋冭瘯鏈熼棿锛屼細璁?NDK鑷?姩鐢熸垚鏈夌敤鐨勬暟鎹?枃浠?/span>銆?/div>
锛?锛塋OCAL_CXXFLAGS:聽涓?LOCAL_CFLAGS鍚岀悊锛岄拡瀵?C++婧愭枃浠躲??/span>
锛?锛塋OCAL_CPPFLAGS:涓?LOCAL_CFLAGS鍚岀悊锛屼絾鏄?? C 鍜?C++ source files閮介??/span>鐢ㄣ??/span>
锛?锛塋OCAL_STATIC_LIBRARIES:琛ㄧず璇ユā鍧楅渶瑕佷娇鐢ㄥ摢浜涢潤鎬佸簱锛屼互渚垮湪缂栬瘧鏃惰繘琛岄摼鎺ャ??/span>
锛?0锛塋OCAL_SHARED_LIBRARIES:聽琛ㄧず妯″潡鍦ㄨ繍琛屾椂瑕佷緷璧栫殑鍏变韩搴擄紙鍔ㄦ?佸簱锛夛紝鍦ㄩ摼鎺ユ椂灏遍渶瑕侊紝浠ヤ究鍦ㄧ敓鎴愭枃浠舵椂宓屽叆鍏剁浉搴旂殑淇℃伅銆傛敞鎰忥細瀹冧笉浼氶檮鍔犲垪鍑虹殑妯″潡鍒扮紪璇戝浘锛屼篃灏辨槸浠嶇劧闇?瑕佸湪Application.mk 涓?妸瀹冧滑娣诲姞鍒扮▼搴忚?姹傜殑妯″潡涓???/span>
锛?1锛塋OCAL_LDLIBS:聽缂栬瘧妯″潡鏃惰?浣跨敤鐨勯檮鍔犵殑閾炬帴鍣ㄩ?夐」銆傝繖瀵逛簬浣跨敤鈥?/span>-l鈥?/span>鍓嶇紑浼犻?掓寚瀹氬簱鐨勫悕瀛楁槸鏈夌敤鐨勩??/span>
渚嬪?锛?/span>LOCAL_LDLIBS := -lz琛ㄧず鍛婅瘔閾炬帴鍣ㄧ敓鎴愮殑妯″潡瑕佸湪鍔犺浇鏃跺埢閾炬帴鍒?/span>/system/lib/libz.so
聽 鍙?煡鐪?docs/STABLE-APIS.TXT 鑾峰彇浣跨敤 NDK鍙戣?鐗堣兘閾炬帴鍒扮殑寮?鏀剧殑绯荤粺搴撳垪琛ㄣ??/span>
锛?2锛?LOCAL_ALLOW_UNDEFINED_SYMBOLS:聽榛樿?鎯呭喌涓嬶紝 鍦ㄨ瘯鍥剧紪璇戜竴涓?叡浜?簱鏃讹紝浠讳綍鏈?畾涔夌殑寮曠敤灏嗗?鑷翠竴涓??滄湭瀹氫箟鐨勭?鍙封?濋敊璇??傝繖瀵逛簬鍦ㄦ簮浠g爜鏂囦欢涓?崟鎹夐敊璇?細鏈夊緢澶х殑甯?姪銆傜劧鑰岋紝濡傛灉鍥犱负鏌愪簺鍘熷洜锛岄渶瑕佷笉鍚?姩杩欓」妫?鏌ワ紝鍙?妸杩欎釜鍙橀噺璁句负鈥榯rue鈥欍??/span>
娉ㄦ剰鐩稿簲鐨勫叡浜?簱鍙?兘鍦ㄨ繍琛屾椂鍔犺浇澶辫触銆?杩欎釜涓?鑸?敖閲忎笉瑕佸幓璁句负 true)銆?/span>
锛?3锛?LOCAL_ARM_MODE:榛樿?鎯呭喌涓嬶紝 arm鐩?爣浜岃繘鍒朵細浠?thumb 鐨勫舰寮忕敓鎴?16 浣?锛屼綘鍙?互閫氳繃璁剧疆杩欎釜鍙橀噺涓?arm濡傛灉浣犲笇鏈涗綘鐨?module 鏄?互 32 浣嶆寚浠ょ殑褰㈠紡銆?/span>
'arm' (32-bit instructions) mode. E.g.:
LOCAL_ARM_MODE := arm
娉ㄦ剰锛氬彲浠ュ湪缂栬瘧鐨勬椂鍊欏憡璇夌郴缁熼拡瀵规煇涓?簮鐮佹枃浠惰繘琛岀壒瀹氱殑绫诲瀷鐨勭紪璇?/span>
姣斿?锛孡OCAL_SRC_FILES := foo.c bar.c.arm 聽杩欐牱灏卞憡璇夌郴缁熸?绘槸灏?bar.c 浠?/span>arm鐨勬ā寮忕紪璇戙??/span>
(14)LOCAL_MODULE_PATH 鍜?LOCAL_UNSTRIPPED_PATH
鍦?Android.mk 鏂囦欢涓?紝 杩樺彲浠ョ敤LOCAL_MODULE_PATH鍜?/span>LOCAL_UNSTRIPPED_PATH鎸囧畾鏈?鍚庣殑鐩?爣瀹夎?璺?緞.
涓嶅悓鐨勬枃浠剁郴缁熻矾寰勭敤浠ヤ笅鐨勫畯杩涜?閫夋嫨锛?/span>
TARGET_ROOT_OUT锛氳〃绀烘牴鏂囦欢绯荤粺銆?/div>
聽 聽TARGET_OUT锛氳〃绀?system鏂囦欢绯荤粺銆?/div>
聽TARGET_OUT_DATA锛氳〃绀?data鏂囦欢绯荤粺銆?/div>
鐢ㄦ硶濡傦細LOCAL_MODULE_PATH :=$(TARGET_ROOT_OUT)聽
鑷充簬LOCAL_MODULE_PATH 鍜孡OCAL_UNSTRIPPED_PATH鐨勫尯鍒?紝鏆傛椂杩樹笉娓呮?銆?/span>
涓冦?丟NU Make鈥樺姛鑳解?欏畯
GNU Make鈥樺姛鑳解?欏畯锛屽繀椤婚?氳繃浣跨敤'$(call 聽)'鏉ヨ皟鐢?紝璋冪敤浠栦滑灏嗚繑鍥炴枃鏈?寲鐨勪俊鎭???/span>
锛?锛塵y-dir:杩斿洖褰撳墠 Android.mk 鎵?鍦ㄧ殑鐩?綍鐨勮矾寰勶紝鐩稿?浜?NDK 缂栬瘧绯荤粺鐨勯《灞傘?傝繖鏄?湁鐢ㄧ殑锛屽湪 Android.mk 鏂囦欢鐨勫紑澶村?姝ゅ畾涔夛細
LOCAL_PATH := $(call my-dir)
锛?锛塧ll-subdir-makefiles:杩斿洖涓?涓?綅浜庡綋鍓?my-dir'璺?緞鐨勫瓙鐩?綍涓?殑鎵?鏈堿ndroid.mk鐨勫垪琛?/span>銆?/div>
渚嬪?锛岀湅涓嬮潰鐨勭洰褰曞眰娆★細
sources/foo/Android.mk
sources/foo/lib1/Android.mk
sources/foo/lib2/Android.mk
聽濡傛灉 sources/foo/Android.mk 鍖呭惈涓?琛岋細
include $(call all-subdir-makefiles)
閭d箞瀹冨氨浼氳嚜鍔ㄥ寘鍚?sources/foo/lib1/Android.mk 鍜?sources/foo/lib2/Android.mk銆?/span>
杩欓」鍔?/span>鑳界敤浜庡悜缂栬瘧绯荤粺鎻愪緵娣卞眰娆″祵濂楃殑浠g爜鐩?綍灞傛?銆?/span>
娉ㄦ剰锛?span style="line-height: 28px; color: #000080;">鍦ㄩ粯璁ゆ儏鍐典笅锛孨DK 灏嗕細鍙?悳绱㈠湪 sources/*/Android.mk 涓?殑鏂囦欢銆?/span>
锛?锛塼his-makefile:杩斿洖褰撳墠Makefile 鐨勮矾寰?鍗宠繖涓?嚱鏁拌皟鐢ㄧ殑鍦版柟)
锛?锛塸arent-makefile:杩斿洖璋冪敤鏍戜腑鐖?Makefile 璺?緞銆傚嵆鍖呭惈褰撳墠Makefile鐨凪akefile 璺?緞銆?/span>
锛?锛塯rand-parent-makefile锛?span style="line-height: 28px; color: #000080;">杩斿洖璋冪敤鏍戜腑鐖禡akefile鐨勭埗Makefile鐨勮矾寰?/span>
鍏???Android.mk 浣跨敤妯℃澘
鍦ㄤ竴涓?Android.mk 涓?彲浠ョ敓鎴愬?涓狝PK搴旂敤绋嬪簭锛孞AVA搴擄紝C\C++鍙?墽琛岀▼搴?C\C++鍔ㄦ?佸簱鍜孋\C++闈欐?佸簱銆?/span>
锛?strong style="line-height: 28px;">1锛夌紪璇慉PK搴旂敤绋嬪簭妯℃澘銆?/strong>
鍏充簬缂栬瘧APK搴旂敤绋嬪簭鐨勬ā鏉胯?鍙傜収銆?a href="/blog/2089158">Android.mk缂栬瘧APK鑼冧緥銆?/div>
锛?锛夌紪璇慗AVA搴撴ā鏉?/strong>
聽 LOCAL_PATH := $(call my-dir)
聽 include $(CLEAR_VARS)
# Build all java files in the java subdirectory
聽 LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES := android.test.runner
# The name of the jar file to create
聽 LOCAL_MODULE := sample
# Build a static jar file.
聽 include $(BUILD_STATIC_JAVA_LIBRARY)
娉?/strong>锛歀OCAL_JAVA_LIBRARIES := android.test.runner琛ㄧず鐢熸垚鐨凧AVA搴撶殑jar鏂囦欢鍚?/div>
锛?锛夌紪璇慍/C++搴旂敤绋嬪簭妯℃澘濡備笅锛?/div>
LOCAL_PATH := $(call my-dir)
#include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := test_exe
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_EXECUTABLE)
娉?/strong>锛氣??=鈥欐槸璧嬪?肩殑鎰忔?濓紝'+='鏄?拷鍔犵殑鎰忔?濓紝鈥?鈥欒〃绀哄紩鐢ㄦ煇鍙橀噺鐨勫??/div>
LOCAL_SRC_FILES涓?姞鍏ユ簮鏂囦欢璺?緞锛孡OCAL_C_INCLUDES涓?姞鍏ラ渶瑕佺殑澶存枃浠舵悳绱㈣矾寰?/span>
LOCAL_STATIC_LIBRARIES鍔犲叆鎵?闇?瑕侀摼鎺ョ殑闈欐?佸簱(*.a)鐨勫悕绉帮紝
LOCAL_SHARED_LIBRARIES涓?姞鍏ユ墍闇?瑕侀摼鎺ョ殑鍔ㄦ?佸簱(*.so)鐨勫悕绉帮紝
LOCAL_MODULE琛ㄧず妯″潡鏈?缁堢殑鍚嶇О锛?/span>BUILD_EXECUTABLE琛ㄧず浠ヤ竴涓?彲鎵ц?绋嬪簭鐨勬柟寮忚繘琛岀紪璇戙??/span>
锛?锛夌紪璇慍\C++闈欐?佸簱
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
聽helloworld.c
LOCAL_MODULE:= libtest_static
聽#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_STATIC_LIBRARY)
鍜屼笂闈㈢浉浼硷紝BUILD_STATIC_LIBRARY 琛ㄧず缂栬瘧涓?涓?潤鎬佸簱銆?/span>
锛?锛夌紪璇慍\C++鍔ㄦ?佸簱鐨勬ā鏉?/strong>
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := helloworld.c
LOCAL_MODULE := libtest_shared
TARGET_PRELINK_MODULES := false
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_SHARED_LIBRARY)
鍜屼笂闈㈢浉浼硷紝BUILD_SHARED_LIBRARY 琛ㄧず缂栬瘧涓?涓?叡浜?簱銆?/span>
浠ヤ笂涓夎?呯殑鐢熸垚缁撴灉鍒嗗埆鍦ㄥ?涓嬬洰褰曚腑锛実eneric 渚濆叿浣?target 浼氬彉锛?/div>
out/target/product/generic/obj/APPS
out/target/product/generic/obj/JAVA_LIBRARIES
out/target/product/generic/obj/EXECUTABLE
out/target/product/generic/obj/STATIC_LIBRARY
out/target/product/generic/obj/SHARED_LIBRARY
姣忎釜妯″潡鐨勭洰鏍囨枃浠跺す鍒嗗埆涓?/span>锛?/div>
1锛?/span>APK绋嬪簭锛歑XX_intermediates
2锛?/span>JAVA搴撶▼搴?/span>锛歑XX_intermediates
杩欓噷鐨刋XX
聽3锛?/span>C\C++鍙?墽琛岀▼搴?/span>锛歑XX_intermediates
聽4锛?/span>C\C++闈欐?佸簱锛?XXX_static_intermediates
聽5锛?/span>C\C++鍔ㄦ?佸簱锛?XXX_shared_intermediates
  相关解决方案