【问题标题】:Android studio doesn't appear to be reading .mk filesAndroid Studio 似乎没有读取 .mk 文件
【发布时间】:2015-08-19 17:05:07
【问题描述】:

我正在使用启用了 experimental ndk plugin 的 Android Studio 1.3。我试图通过将 Box2d 文件夹放入 jni 文件夹来编译 Box2d。我那里也有 Android.mk 和 Application.mk。每当我尝试编译 Android Studio 时都会吐出找不到头文件的错误。似乎无论我对 .mk 文件做什么,都没有任何改变。就好像他们甚至没有被阅读。 Android studio 会读取 .mk 文件吗?

LOCAL_PATH:=$(call my-dir)
$(info $(LOCAL_PATH))
source_directories:=\
    Collision \
    Collision/Shapes \
    Common \
    Dynamics \
    Dynamics/Contacts \
    Dynamics/Joints \
    Particle \
    Rope

include $(LOCAL_PATH)/b2_android_common.mk

# Conditionally include libstlport (so include path is added to CFLAGS) if
# it's not being built using the NDK build process.
define add-stlport-includes
$(eval \
  ifeq ($(NDK_PROJECT_PATH),)
  include external/stlport/libstlport.mk
  endif)
endef

# Configure common local variables to build box2d adding $(1) to the end of the
# build target's name.
define box2d-module
$(eval \
  LOCAL_MODULE:=libliquidfun$(1)
  LOCAL_MODULE_TAGS:=optional
  LOCAL_COPY_HEADERS_TO:=liquidfun$(1))
endef

# Execute a shell command relative to this module's directory.
define execute-local
$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; eval "$(1)"))
endef

# Configure local variables to build box2d adding $(1) to the end of the
# build target's name.
define box2d-build
$(eval \
  $$(call box2d-module,$(1))
  LOCAL_SRC_FILES:=\
    $(subst $(LOCAL_PATH)/,,\
      $(foreach source_dir,$(source_directories),\
        $(foreach extension,$(b2_extensions),\
          $(wildcard $(LOCAL_PATH)/Box2D/$(source_dir)/*.$(extension)))))
  LOCAL_COPY_HEADERS:=\
    Box2D/Box2D.h \
    $(subst $(LOCAL_PATH)/,,\
      $(foreach source_dir,$(source_directories),\
        $(wildcard $(LOCAL_PATH)/Box2D/$(source_dir)/*.h)))
  LOCAL_CFLAGS:=$(if $(APP_DEBUG),-DDEBUG=1,-DDEBUG=0) $(b2_cflags)
  LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
  LOCAL_ARM_MODE:=arm
  $$(call add-stlport-includes))
endef

# --- libliquidfun ---
# Build shared library.
include $(CLEAR_VARS)
$(call box2d-build,)
include $(BUILD_SHARED_LIBRARY)

# --- libliquidfun_static ---
# Build static library.
include $(CLEAR_VARS)
$(call box2d-build,_static)
include $(BUILD_STATIC_LIBRARY)

【问题讨论】:

    标签: android android-studio makefile android-ndk android-make


    【解决方案1】:

    不,Android Studio 不读取 *.mk 文件。

    它会自动为您在 jni/ 下的所有源文件生成 Makefile,按照您可以在 build.gradle 中执行的配置。

    你可以尝试用这种方式编译 box2d。您必须编写这样的配置:

    android.ndk {
        //...
        stl = stlport_static
        cppFlags += "-I${file("src/main/jni/Box2D/Collision")}".toString() // extra includes
        //...
    }
    

    否则,如果您想考虑您的 Makefile,您可以自己致电ndk-build。在你的 build.gradle 中设置它,这样它就不会尝试编译你的代码,它会从 src/main/libs/ 获取你的 .so 文件:

    android.sources{
        main.jni {
            source {
                srcDirs = ['src/main/none'] // [] could be set instead but will disable even symbol resolution inside the editor
            }
        }
        main.jniLibs {
            source {
                srcDirs = ['src/main/libs']
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多