Skip to content

Commit

Permalink
feat(core): add dynamic load
Browse files Browse the repository at this point in the history
  • Loading branch information
churchill-zhang committed Dec 25, 2020
1 parent 34ba5cf commit 20e2ed9
Show file tree
Hide file tree
Showing 165 changed files with 32,140 additions and 3,994 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ layout/cproject
layout/.project
layout/.settings
examples/*/res/vendor-manifest.json
android/sdk/src/main/jni/core
android/sdk/src/main/jni/.vs
android/sdk/maven-auth.properties
android/sdk/libs/hippy.jar
examples/android-demo/example/src/main/assets/
examples/ios-demo/HippyDemo.xcodeproj/project.xcworkspace/xcuserdata/*
examples/ios-demo/HippyDemo.xcodeproj/xcuserdata/*
examples/hippy-react-demo/package-lock.json
examples/hippy-vue-demo/package-lock.json
examples/android-demo/maven-auth.properties

# android
*.iml
Expand All @@ -27,3 +28,6 @@ local.properties
.gradle/
build/
.externalNativeBuild

# core
core/ARM
32 changes: 13 additions & 19 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ext {
ndkDir = properties.getProperty('ndk.dir')
sdkDir = properties.getProperty('sdk.dir')

v8Version = "v8_72"
// Visual Studio Debugging Support
skipCmakeAndNinja = System.getenv('skipCmakeAndNinja') != null
}
Expand Down Expand Up @@ -72,16 +73,7 @@ def findCmakeBuildPath() {
return findCmakeBinPath() + "/cmake"
}

task deleteCore(type: Delete) {
delete 'src/main/jni/core'
}

task copyCore(dependsOn: deleteCore, type: Copy) {
from '../../core'
into 'src/main/jni/core'
}

task compileCmake(dependsOn: copyCore, type: Exec) {
task compileCmake(type: Exec) {
def cMakeWorkDir = file(project.buildDir.absolutePath + "/cmakeoutput")
cMakeWorkDir.deleteDir()
cMakeWorkDir.mkdirs()
Expand All @@ -94,15 +86,17 @@ task compileCmake(dependsOn: copyCore, type: Exec) {
// def arches = ["arm64-v8a"]
for (arch in arches) {
commandLine findCmakeBuildPath(),
"-DJS_ENGINE=V8",
"-DANDROID_ABI=${arch}",
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$project.buildDir.absolutePath/outputs/${arch}/",
"-DANDROID_TOOLCHAIN=clang",
"-DANDROID_CPP_FEATURES=rtti exceptions",
"-DANDROID_NDK=${findNdkFullPath()}",
"-DANDROID_PLATFORM=android-14",
"-DCMAKE_BUILD_TYPE=Release",
"-DV8_VERSION=${v8Version}",
"-DCMAKE_TOOLCHAIN_FILE=${findToolChainPath()}",
"-G", "Android Gradle - Ninja", file("src/main/jni/${arch}").absolutePath
"-G", "Android Gradle - Ninja", file("src/main/jni/").absolutePath
}

}
Expand Down Expand Up @@ -165,7 +159,7 @@ def getToolPathX86_64(String toolName) {
}
return findNdkFullPath() + "/toolchains/x86_64-4.9/prebuilt/" + fileName + "/bin/" + toolName
}
task stripSO(dependsOn: compileNinja, type: Exec) {
task stripSO(dependsOn: (skipCmakeAndNinja.toBoolean() ? skipCmakeAndNinjaTask : compileNinja), type: Exec) {
commandLine getToolPath("arm-linux-androideabi-strip"),
"--strip-all",
"-x",
Expand Down Expand Up @@ -223,31 +217,31 @@ task address2Line(type: Exec) {
"-C",
"-f",
"-e",
project.buildDir.absolutePath + "/outputs/libhippybridge.so",
project.buildDir.absolutePath + "/outputs/armeabi-v7a/libhippybridge.so",
address
}

task buildNdkLibs(dependsOn: (ISCI.toBoolean() ? dealNdkLibSymbols : stripSO)) {
copy {
from "src/main/jni/third_party/v8/x86"
from "src/main/jni/third_party/${v8Version}/v8/x86"
into "$buildDir/jnilibs/x86/"
}
copy {
from "src/main/jni/third_party/v8/x86_64"
from "src/main/jni/third_party/${v8Version}/v8/x86_64"
into "$buildDir/jnilibs/x86_64/"
}

copy {
from "src/main/jni/third_party/v8/arm64-v8a"
from "src/main/jni/third_party/${v8Version}/v8/arm64-v8a"
into "$buildDir/jnilibs/arm64-v8a/"
}

copy {
from "src/main/jni/third_party/v8/armeabi-v7a"
from "src/main/jni/third_party/${v8Version}/v8/armeabi-v7a"
into "$buildDir/jnilibs/armeabi-v7a/"
}
copy {
from "src/main/jni/third_party/v8/armeabi-v7a"
from "src/main/jni/third_party/${v8Version}/v8/armeabi-v7a"
into "$buildDir/jnilibs/armeabi/"
}
}
Expand Down Expand Up @@ -276,7 +270,7 @@ android {
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
Expand Down
Binary file modified android/sdk/libs/armeabi-v7a/libhippybridge.so
Binary file not shown.
Empty file modified android/sdk/libs/x86_64/libhippybridge.so
100755 → 100644
Empty file.
114 changes: 114 additions & 0 deletions android/sdk/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(ABI_COMPILE_OPTIONS
-fno-rtti
-fno-threadsafe-statics
-fvisibility-inlines-hidden
-std=c++14
--param=ssp-buffer-size=4
-Werror
-fno-exceptions
-fno-strict-aliasing
-Wall
-fexceptions
-Wno-unused-parameter
-Wno-missing-field-initializers
-pipe
-fPIC
-Wno-unused-local-typedefs
-funwind-tables
-fstack-protector
-fno-short-enums
-Os
-g
-fdata-sections
-ffunction-sections
-fomit-frame-pointer
)

message("ANDROID_ABI: ${ANDROID_ABI}")
if (${ANDROID_ABI} STREQUAL "armeabi-v7a")
set(ABI_COMPILE_OPTIONS
${ABI_COMPILE_OPTIONS}
-march=armv7-a
-mtune=generic-armv7-a
-mfpu=vfpv3-d16
-mfloat-abi=softfp
-mthumb
)
elseif (${ANDROID_ABI} STREQUAL "arm64-v8a")

elseif (${ANDROID_ABI} STREQUAL "x86")
set(ABI_COMPILE_OPTIONS
${ABI_COMPILE_OPTIONS}
-march=i686
-mtune=intel
-m32
-mssse3
-mfpmath=sse
)
elseif (${ANDROID_ABI} STREQUAL "x86_64")
set(ABI_COMPILE_OPTIONS
${ABI_COMPILE_OPTIONS}
-march=x86-64
-mtune=intel
-m64
-mpopcnt
-msse4.2
)
else()
message("${ANDROID_ABI} is not supported")
endif()
message("ABI_COMPILE_OPTIONS: ${ABI_COMPILE_OPTIONS}")


add_definitions("-DOS_ANDROID")

add_compile_options(${ABI_COMPILE_OPTIONS})


get_filename_component(CORE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../core" REALPATH)

file(GLOB_RECURSE CORE_SRC ${CORE_SRC_DIR}/src/*.cc)
file(GLOB_RECURSE JNI_SRC ${PROJECT_SOURCE_DIR}/src/*.cc)

message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message("CORE_SRC_DIR: ${CORE_SRC_DIR}")
message("JNI_SRC: ${JNI_SRC}")
message("V8_VERSION: ${V8_VERSION}")

message("JS_ENGINE:" ${JS_ENGINE})
if (${JS_ENGINE} STREQUAL "V8")
file(GLOB_RECURSE JSC_SRC ${CORE_SRC_DIR}/src/napi/jsc/*)
message("JSC_SRC: ${JSC_SRC}")
list(REMOVE_ITEM CORE_SRC ${JSC_SRC})
elseif (${JS_ENGINE} STREQUAL "JSC")
file(GLOB_RECURSE V8_SRC ${CORE_SRC_DIR}/src/napi/v8/*)
message("V8_SRC: ${V8_SRC}")
list(REMOVE_ITEM CORE_SRC ${V8_SRC})
else()
message("${JS_ENGINE} is not supported")
endif()
message("CORE_SRC: ${CORE_SRC}")

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")

include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${CORE_SRC_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/third_party/${V8_VERSION})
include_directories(${PROJECT_SOURCE_DIR})

add_library(libmttv8 SHARED IMPORTED)
set_target_properties(libmttv8 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/third_party/${V8_VERSION}/v8/${ANDROID_ABI}/libmttv8.so)

add_library(libmtt_shared SHARED IMPORTED)
set_target_properties(libmtt_shared PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/third_party/${V8_VERSION}/v8/${ANDROID_ABI}/libmtt_shared.so)

add_library(hippybridge SHARED ${CORE_SRC} ${URL_PARSER_SRC} ${JNI_SRC})
target_link_libraries(hippybridge android log libmttv8 libmtt_shared)

set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG " )
18 changes: 18 additions & 0 deletions android/sdk/src/main/jni/HippyAndroidSdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.28803.452
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HippyAndroidSdk", "HippyAndroidSdk.vcxproj", "{E0581439-C51A-4F6C-9ABF-D697C33333B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "..\..\..\..\..\core\core.vcxproj", "{33620009-97B0-440A-88C7-AF0AFD05DAD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -35,6 +37,22 @@ Global
{E0581439-C51A-4F6C-9ABF-D697C33333B0}.Release|x64.Build.0 = Release|x64
{E0581439-C51A-4F6C-9ABF-D697C33333B0}.Release|x86.ActiveCfg = Release|x86
{E0581439-C51A-4F6C-9ABF-D697C33333B0}.Release|x86.Build.0 = Release|x86
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|ARM.ActiveCfg = Debug|ARM
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|ARM.Build.0 = Debug|ARM
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|ARM64.ActiveCfg = Debug|ARM64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|ARM64.Build.0 = Debug|ARM64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|x64.ActiveCfg = Debug|x64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|x64.Build.0 = Debug|x64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|x86.ActiveCfg = Debug|x86
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Debug|x86.Build.0 = Debug|x86
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|ARM.ActiveCfg = Release|ARM
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|ARM.Build.0 = Release|ARM
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|ARM64.ActiveCfg = Release|ARM64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|ARM64.Build.0 = Release|ARM64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|x64.ActiveCfg = Release|x64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|x64.Build.0 = Release|x64
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|x86.ActiveCfg = Release|x86
{33620009-97B0-440A-88C7-AF0AFD05DAD8}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 20e2ed9

Please sign in to comment.