在C語言中 h 檔除了可以讓程式更有結構及維護性外,在Android使用中你可以將C原始檔編譯成 library檔,然後把library檔及標頭檔(h檔)提供給需要的人,這樣同時可以讓其他人使用;亦可保有原始碼程式不被人看到,這種情況經常在呼叫硬體時為避免其他廠商從原始碼抄襲硬體而做的保護方式之一。
由於程式碼可以在..\android-ndk-r7b\samples\two-libs目錄可以看到所以這次就不貼程式碼,整個執行的架構如下圖所示:

由於two-libs沒有.project及.classpath檔案,
所以要import到Eclipse時會找不到專案(File -->Import-->General-->Existing Projects into Workspace -->Select root directory -->.....)

這個時候換一個方式進行程式的匯入:
New-->Android Project 選擇 Create project from existing source (其他資訊參考下圖所示,Project Name不填寫的話會自動命名)

然後用ndk-build編譯


執行結果:

沒有留言:
張貼留言