본문 바로가기

구글과인터넷/안드로이드

안드로이드 android NDK jni 폴더안에 폴더를 만들어 빌드해보기

JNI 을 할떄 코드들이 jni 한 폴더에 만 있어 정리하기 곤란할때가 있다.

그러면 아래 그림처럼 처리 해주면 도움이 된다.




http://202psj.tistory.com/

LOCAL_PATH := $(call my-dir)


include $(CLEAR_VARS)


LS_CPP=$(subst $(1)/,,$(wildcard $(1)/*.cpp))

LOCAL_MODULE    := droidblaster

LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH)) \

 ./basea/TimeService.h \

 ./basea/TimeService.cpp \


LOCAL_LDLIBS    := -landroid -llog -lEGL -lGLESv1_CM


LOCAL_STATIC_LIBRARIES := android_native_app_glue png


include $(BUILD_SHARED_LIBRARY)


$(call import-module,android/native_app_glue)

$(call import-module,libpng)

#-----------------------------------------------------------------------------------


LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH)) \

이부분은 기본 jni 폴더 기본 부분이고

 ./basea/TimeService.h \

 ./basea/TimeService.cpp \

이부분은 폴더 생성뒤 정리한 추가 부분이다.


더 효율적인 방법이 있는 것 같은데 자꾸 에러가 나서 

더 연구해보구 더 올려야 겠다 ㅋㅋ 

더 좋은 방법 아시는분 리플 부탁 드립니다~!


추가

-------------------------------------------------------------

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)


LS_CPP=$(subst $(1)/,,$(wildcard $(1)/*.cpp))

LS_CPP2=$(subst $(1)/,,$(wildcard $(1)/basea/*.cpp))


LOCAL_MODULE    := droidblaster

LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH)) \

 $(call LS_CPP2,$(LOCAL_PATH)) \


LOCAL_LDLIBS    := -landroid -llog -lEGL -lGLESv1_CM

LOCAL_STATIC_LIBRARIES := android_native_app_glue png

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

$(call import-module,libpng)

----------------------------

 ./basea/TimeService.h \

 ./basea/TimeService.cpp 

대신

LS_CPP2=$(subst $(1)/,,$(wildcard $(1)/basea/*.cpp))

여기에 폴더를 지정해주고

LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH)) \

 $(call LS_CPP2,$(LOCAL_PATH)) \

이런식으로 불러오는 것도 됩니다 ^^



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


출처: http://www.cocos2d-x.org/boards/6/topics/5321

edisun dongis there are way to create android.mk automatically
Posts4
edisun dong이(가) 약 일년 전에 추가함

the file is look like :

LOCAL_SRC_FILES := main.cpp \
../../../Classes/AppDelegate.cpp \
../../../Classes/GameMenu/GameMainMenu.cpp \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
$(LOCAL_PATH)/../../../../cocos2dx/platform \
$(LOCAL_PATH)/../../../../cocos2dx/include \
$(LOCAL_PATH)/../../../../CocosDenshion/include \
$(LOCAL_PATH)/../../../Classes \
$(LOCAL_PATH)/../../../Classes/GameMenu

so any class i add ,i must modify the android.mk file,is any tool can fix that??

Minggo ZhangRE: is there are way to create android.mk automatically
Posts1499
Minggo Zhang이(가) 약 일년 전에 추가함

No now, may be you can write a script to do it and share with the community.

edisun dongRE: is there are way to create android.mk automatically
Posts4
edisun dong이(가) 약 일년 전에 추가함

OK,i will ,but not today,and i am not so good at shell,may be i will use .exe(windows) or .app(mac os),sorry linux guys :)

Victor LavrentyevRE: is there are way to create android.mk automatically
Posts5
Victor Lavrentyev이(가) 11달 전에 추가함
Include all *.cpp files automatically in Android.mk:
  • For Android.mk in "/Classes" folder (or you must correct the script)
  • If I want to rebuild project I resave Android.mk (this maybe dummy way) or you need to use the "always_rebuild" key (I don't know it)
    define all-cpp-files-under
    $(patsubst ./%,%, \
      $(shell cd $(LOCAL_PATH) ; \
              find $(1) -name "*.cpp" -and -not -name ".*") \
     )
    endef
    
    define all-subdir-cpp-files
    $(call all-cpp-files-under,.)
    endef
    
    LOCAL_SRC_FILES += $(call all-subdir-cpp-files)
    

Maybe I should share this in other place?

小 苏RE: is there are way to create android.mk automatically
Posts68
小 苏이(가) 11달 전에 추가함

it's good..

Victor LavrentyevRE: is there are way to create android.mk automatically
Posts5
Victor Lavrentyev이(가) 11달 전에 추가함

O!
I found "../HelloWorld/android/jni/list.sh" with function list_alldir().
It look like useful for this issue, but don't used by default... strange.

FoXx WeLlRE: is there are way to create android.mk automatically
Posts8
FoXx WeLl이(가) 11달 전에 추가함

OK~ I fix android.mk to create android.mk automatically~
It can find any subdirs and *.cpp that u add in "Classes"

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_logic

dirs := $(shell find $(LOCAL_PATH) -type d)

cppfilestemp1 := $(shell find $(LOCAL_PATH) -type d)
cppfilestemp2 := $(shell find $(cppfilestemp1) -name *.cpp)
cppfilestemp3 := $(sort $(cppfilestemp2))
cppfiles := $(subst $(LOCAL_PATH)/,,$(cppfilestemp3))

LOCAL_SRC_FILES := \
           $(cppfiles)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../cocos2dx \
                    $(LOCAL_PATH)/../../cocos2dx/platform \
                    $(LOCAL_PATH)/../../cocos2dx/include \
                    $(LOCAL_PATH)/../../CocosDenshion/include \
                    $(LOCAL_PATH)/../../cocos2dx/lua_support \
            $(dirs)

It's for cocos2d-1.0.1-x-0.10.0 !!!

or u can download file and cover it

Android.mk (994 Bytes)

aries sulitRE: is there are way to create android.mk automatically
Posts3
aries sulit이(가) 9일 전에 추가함

Hi!

Is it okay for .mm classes? cause i have .mm classes on my iphone cocos2d-x project,
and after i modified Android.mk file. I got this error.

Compile++ thumb : game <= ClassicGameplay.mm
fatal error: directory compilation terminated.
make: *** [obj/local/armeabi/objs-debug/game/__/__/__/__/source/states/ClassicGameplay.o] Error 1
ERROR: NDK build failed.

Pipero ManRE: is there are way to create android.mk automatically
Posts55
Pipero Man이(가) 9일 전에 추가함

My Android.mk looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

FILE_LIST := $(wildcard $(LOCAL_PATH)/../../Classes/Actions/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Constants/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Helpers/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/GameObjects/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Scenes/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Singletons/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/JNICalls/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)

LOCAL_SRC_FILES := helloworld/main.cpp

LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)

Compile all cpp in each folder. It is helpful if you add new cpps and don't want to add manually (but folders must be). All headers are relatives.

Victor LavrentyevRE: is there are way to create android.mk automatically
Posts5
Victor Lavrentyev이(가) 9일 전에 추가함

hm...
1. Android don't understands Obj C language
2. "-name *.cpp" - it takes cpp files only

aries sulitRE: is there are way to create android.mk automatically
Posts3
aries sulit이(가) 8일 전에 추가함

Hi! so.. I badly need to convert obj-c codes to c++ D:
Thanks BTW! :D