最近在學習NDK的時候,使用到SWIG工具的時候,將SWIG集成到Android構建過程中的時候,構建了一個my-swig-generate.mk的Makefile文件,代碼如下:
#
#Android構建系統的SWIG擴展
#
#檢查變量 MY_SWIG_PACKAGE 是否已經定義
ifndef MY_SWIG_PACKAGE
$(error MY_SWIG_PACKAGE is not defined.)
endif
#用斜線替換java目錄中的圓點
MY_SWIG_OUTDIR:= $(NDK_PROJECT_PATH)/src/$(subst .,/,$(MY_SWIG_PACKAGE))
#SWIG的默認類型是C
ifndef MY_SWIG_TYPE
MY_SWIG_TYPE := c
endif
#設置SWIG模式
ifeq ($(MY_SWIG_TYPE),cxx)
MY_SWIG_MODE := -c++
else
MY_SWIG_MODE :=
endif
#追加SWIG封裝源文件
LOCAL_SRC_FILES += $(foreach MY_SWIG_INTERFACE,\
$(MY_SWIG_INTERFACES),\
$(basename $(MY_SWIG_INTERFACE))_wrap.$(MY_SWIG_TYPE))
#添加.cxx作爲c++擴展名
LOCAL_CPP_EXTENSION += .cxx
#生成SWIG封閉代碼(indention should be tabs for this block)
%_wrap.$(MY_SWIG_TYPE) : %.i
$(call host-mkdir,$(MY_SWIG_OUTDIR))
swig -java \
$(MY_SWIG_MODE) \
-package $(MY_SWIG_PACKAGE) \
-outdir $(MY_SWIG_OUTDIR) \
$<
然後將SWIG集成到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_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
MY_SWIG_PACKAGE := com.apress.swig
MY_SWIG_INTERFACES := Unix.i
MY_SWIG_TYPE := c
include $(LOCAL_PATH)/my-swig-generate.mk
include $(BUILD_SHARED_LIBRARY)
選中項目,在主菜單選擇Project | Build All來重新構建當前的Android項目時,出現了 “*** missing separator. Stop.”這個錯誤:錯誤如下圖所示:
這個錯誤是由於我在編寫這個文件的時候,34行前面用的是空格,而不是tab,所以造成了操作符丟失的錯誤。
解決辦法是:把縮進的空格delete掉,然後按tab鍵用tab代替4個空格。(ps: 下面的35、36、37、38、39也要用tab,不要用空格,不然還是會報錯,而且錯誤居然定位到了34行)