Android Studio 3.0.1不会构建NDK静态库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio 3.0.1不会构建NDK静态库相关的知识,希望对你有一定的参考价值。
我正在尝试在我的android Studio项目中构建并包含一个静态库。我的项目在没有静态库的情况下构建并运行良好。
我的顶级Android.mk包括2个显式的SQLite.mk和Hello.mk行。
我已经在所有这些.mk文件中指定了完整路径,仅仅是为了我自己的理智。
SQLite.mk如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
JNILIB_PATH := C:/androidprojects/SDLTest_SQLite/app/jniLibs
SRC_SQLITE := C:/androidprojects/SDLTest_SQLite/app/jni/SQLite/sqlite3.c
LOCAL_CFLAGS += -Wno-write-strings
LOCAL_MODULE := SQLite
LOCAL_SRC_FILES := $(SRC_SQLITE)
TARGET_OUT=$(JNILIB_PATH)/$(TARGET_ARCH_ABI)
#TARGET_OUT=../jniLibs/$(TARGET_ARCH_ABI)
include $(BUILD_STATIC_LIBRARY)
Android Studio / Gradle错误如下:
Android NDK: ERROR:C:androidprojectsSDLTest_SQLiteappjniAndroid.mk:SQLite: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that C:/androidprojects/SDLTest_SQLite/app/jniLibs/armeabi/libSQLite.a exists or that its path is correct
Build command failed.
我的根本问题是我无法在任何地方生成libSQLite.a文件。我的TARGET_OUT
排队问题了吗?
有人可以帮我生成我的静态库文件吗?
你不应该在Android.mk中设置TARGET_OUT
:这是打破微妙的ndk构建逻辑的可靠方法。你的两个mk文件互不矛盾:SQLite既不能预先构建,也不能从源代码构建。
我不知道为什么你的错误消息说缺少SQLite源,但是你使用了不健康的完整路径。
以下是三个完成工作的mk文件:
Android.门口
ROOT_PATH := $(call my-dir)
include $(ROOT_PATH)/src/Hello.mk
include $(ROOT_PATH)/SQLite/SQLite.mk
SQLite.门口
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
SRC_SQLITE := sqlite3.c
LOCAL_CFLAGS += -Wno-write-strings
LOCAL_MODULE := SQLite
LOCAL_SRC_FILES := $(SRC_SQLITE)
include $(BUILD_STATIC_LIBRARY)
hello.门口
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libSDL2
LOCAL_SRC_FILES := ../../jniLibs/SDL2-prebuilt/$(TARGET_ARCH_ABI)/libSDL2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := main
SDL_PATH := $(LOCAL_PATH)/../../jniLibs/SDL2-prebuilt
LOCAL_C_INCLUDES := $(SDL_PATH)/include
# Add your application source files here...
LOCAL_SRC_FILES := 52_hello_mobile.cpp
LOCAL_STATIC_LIBRARIES := libSDL2 SQLite
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
后者可以稍微改善一下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libSDL2
LOCAL_SRC_FILES := ../../jniLibs/SDL2-prebuilt/$(TARGET_ARCH_ABI)/libSDL2.so
SDL_PATH := $(LOCAL_PATH)/../../jniLibs/SDL2-prebuilt
LOCAL_EXPORT_C_INCLUDES := $(SDL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := main
# Add your application source files here...
LOCAL_SRC_FILES := 52_hello_mobile.cpp
LOCAL_STATIC_LIBRARIES := libSDL2 SQLite
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
还有一个狐狸你的设置:你不能用APP_PLATFORM=14
构建64位版本。您应该使用至少21的compileSdkVersion,并且不要显式设置APP_PLATFORM
。然后,gradle将根据minSdkVersion为32位目标(即APP_PLATFORM
)自动设置android-14
,并将其推送到android-21
以获得64位目标。
在Application.mk中,qazxsw poi设置被默默忽略。
以上是关于Android Studio 3.0.1不会构建NDK静态库的主要内容,如果未能解决你的问题,请参考以下文章
我们如何将CMake或ndk-build集成到Android Studio 3.0.1中? Gradle版本是4.1,android插件版本3.0.1
从 Android Studio 构建替代 buildType 时,ProGuard 不会混淆
Android Studio 3.0.1忽略Application.mk中的APP_ABI?