编译V8静态库 for Android

最新v8Gyp编译已废弃,只支持GN编译。 官网编译文档:


args.gn

is_debug = false
target_cpu = "arm"
v8_target_cpu = "arm"
target_os = "android"
is_component_build = false
v8_static_library = true
v8_enable_i18n_support = false
v8_use_snapshot = false

编译成功后out.gn/xxx/obj/下存在libv8_base.a等静态库。
使用时发现缺少libv8_libplatform.a

连接libv8_libplatform.a

GN的配置我们不用去管,更改现有工程就行。
打开obj/v8_hello_world.ninja,关键连接代码

obj/v8_libbase/bits.o obj/v8_libbase/cpu.o obj/v8_libbase/stack_trace.o obj/v8_libbase/division-by-constant.o obj/v8_libbase/file-utils.o obj/v8_libbase/functional.o obj/v8_libbase/ieee754.o obj/v8_libbase/logging.o obj/v8_libbase/once.o obj/v8_libbase/condition-variable.o obj/v8_libbase/mutex.o obj/v8_libbase/semaphore.o obj/v8_libbase/time.o obj/v8_libbase/sys-info.o obj/v8_libbase/random-number-generator.o obj/v8_libbase/platform-posix.o obj/v8_libbase/stack_trace_android.o obj/v8_libbase/platform-linux.o obj/v8_libplatform/default-platform.o obj/v8_libplatform/task-queue.o obj/v8_libplatform/trace-buffer.o obj/v8_libplatform/trace-config.o obj/v8_libplatform/trace-object.o obj/v8_libplatform/trace-writer.o obj/v8_libplatform/tracing-controller.o obj/v8_libplatform/worker-thread.o

这里的.o文件就是对应libv8_libplatform.a

编辑obj/v8_libsampler.ninja
alink obj/v8_libsampler/sampler.o 后添加上面.o文件。
删除libv8_libsampler.a重新运行ninja -C out.gn/arm.release
生成新的libv8_libsampler.a重命名为libv8_libplatform.a

libv8_base.a
libv8_libplatform.a
libv8_nosnapshot.a

libv8_snapshot.a为Android arm 静态库

静使用

工程目录结构
编译V8静态库 for Android_第1张图片

Application.mk

APP_ABI := armeabi  
NDK_TOOLCHAIN_VERSION=4.9
APP_STL = c++_static
APP_CPPFLAGS := -frtti  -std=c++11 -fsigned-char -fexceptions 
APP_OPTIM := release
APP_PLATFORM := android-16

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := libv8_base
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libv8_base.a
include $(PREBUILT_STATIC_LIBRARY)                 

include $(CLEAR_VARS)
LOCAL_MODULE    := libv8_libplatform
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libv8_libplatform.a
include $(PREBUILT_STATIC_LIBRARY)                     

include $(CLEAR_VARS)
LOCAL_MODULE    := libv8_nosnapshot
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libv8_nosnapshot.a
include $(PREBUILT_STATIC_LIBRARY)                 

include $(CLEAR_VARS)
LOCAL_MODULE    := libv8_snapshot
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libv8_snapshot.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := V8Library
LOCAL_SRC_FILES := V8Library.cpp \
                   JniHelper.cpp \
                   V8Context.cpp \
                   V8ScriptEngine.cpp

LOCAL_CFLAGS := -funwind-tables 

LOCAL_LDLIBS    := -llog -landroid -lstdc++ -lm  -latomic  

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_STATIC_LIBRARIES := libv8_base libv8_libplatform libv8_snapshot   

include $(BUILD_SHARED_LIBRARY)

你可能感兴趣的:(Android,V8)