使用NDK為Android寫linux bin執行程式二三事
阿新 • • 發佈:2019-01-25
寫JNI + Java程式的時候, 有個函式總感覺不對, 想寫個測試程式測試下這個函式. 以前是直接在Jeallybean下面編譯的, 為現有的板子為jeallybean整非ARM的編譯環境也太那個了點, 心想就直接用NDK唄. 然後, 麻煩來了!
1. 如通常一樣,寫hello.cpp測試程式碼
2. ndk-build, 出現NDK_PROJECT_PATH錯誤:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
3. Google+度娘, 好像沒有人說過怎麼處理呢
4. 記得做opencv的時候解決過這個問題, 想想...
5. 想起來了,
mkdir jni
mv *.mk ./jni
mv *.c ./jni
mv *.h ./jni
mv *.cpp ./jni
ndk-build
## 編譯通過, enjoy it.
adb push ../libs/x86/hello /data/
adb shell /data/hello
## 測試結果顯示該函式工作正確, 繼續想想 ...
---------------------------------------------------------
附錄一: Application.mk
---------------------------------------------------------
APP_STL := stlport_static
# APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := x86
---------------------------------------------------------
附錄二: Android.mk
---------------------------------------------------------
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += \
libstdc++ \
sources/cxx-stl/stlport
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libstlport
LOCAL_MODULE := hello
LOCAL_SRC_FILES := hello.cpp
LOCAL_LDLIBS := -lm -llog
include $(BUILD_EXECUTABLE)
1. 如通常一樣,寫hello.cpp測試程式碼
2. ndk-build, 出現NDK_PROJECT_PATH錯誤:
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
3. Google+度娘, 好像沒有人說過怎麼處理呢
4. 記得做opencv的時候解決過這個問題, 想想...
5. 想起來了,
mkdir jni
mv *.mk ./jni
mv *.c ./jni
mv *.h ./jni
mv *.cpp ./jni
ndk-build
## 編譯通過, enjoy it.
adb push ../libs/x86/hello /data/
adb shell /data/hello
## 測試結果顯示該函式工作正確, 繼續想想 ...
---------------------------------------------------------
附錄一: Application.mk
---------------------------------------------------------
APP_STL := stlport_static
# APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := x86
---------------------------------------------------------
附錄二: Android.mk
---------------------------------------------------------
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += \
libstdc++ \
sources/cxx-stl/stlport
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libstlport
LOCAL_MODULE := hello
LOCAL_SRC_FILES := hello.cpp
LOCAL_LDLIBS := -lm -llog
include $(BUILD_EXECUTABLE)