This is an automated email from the ASF dual-hosted git repository. kyork pushed a commit to branch feature/replaceable_JSInterpolator in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
commit f56d9a72225003443f18c99527a549f2ef790735 Author: YorkShen <shenyua...@gmail.com> AuthorDate: Thu Sep 26 14:41:32 2019 +0800 [Android] Make JS Interpolator in Android as replaceable. This will not change the default behavior, as the replace Interpolator will be downloaded to a unused dir. --- android/sdk/.gitignore | 1 + android/sdk/build.gradle | 14 +++++-- android/sdk/buildSrc/download_jsc.gradle | 46 +++++++++++++++++++++ android/sdk/buildSrc/packageName.gradle | 12 ------ .../src/main/java/org/apache/weex/InitConfig.java | 28 ++++++++++++- .../main/java/org/apache/weex/WXEnvironment.java | 29 +++++++------ .../src/main/java/org/apache/weex/WXSDKEngine.java | 2 + .../java/org/apache/weex/utils/WXFileUtils.java | 5 ++- weex_core/Source/CMakeLists.txt | 15 +++---- weex_core/Source/js_runtime/CMakeLists.txt | 18 ++++++-- .../Source/js_runtime/weex/utils/weex_jsc_utils.h | 4 ++ .../Source/libs/arm64-v8a/libJavaScriptCore.so | Bin 9278912 -> 0 bytes weex_core/Source/libs/arm64-v8a/libWTF.so | Bin 522016 -> 0 bytes .../Source/libs/armeabi-v7a/libJavaScriptCore.so | Bin 5237308 -> 0 bytes weex_core/Source/libs/armeabi-v7a/libWTF.so | Bin 472828 -> 0 bytes weex_core/Source/libs/armeabi/libJavaScriptCore.so | Bin 5237308 -> 0 bytes weex_core/Source/libs/armeabi/libWTF.so | Bin 472828 -> 0 bytes weex_core/Source/libs/x86/libJavaScriptCore.so | Bin 13729888 -> 0 bytes weex_core/Source/libs/x86/libWTF.so | Bin 805056 -> 0 bytes 19 files changed, 129 insertions(+), 45 deletions(-) diff --git a/android/sdk/.gitignore b/android/sdk/.gitignore index f29323d..c149ebe 100755 --- a/android/sdk/.gitignore +++ b/android/sdk/.gitignore @@ -17,6 +17,7 @@ assets/weex-rax-api.js .externalNativeBuild /libs/armeabi +/src/main/jniLibs /src/legacyRelease/ proguard-rules-legacy.pro \ No newline at end of file diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index 48b7076..7902b65 100755 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -31,6 +31,7 @@ apply from: 'buildSrc/jcenter.gradle' apply from: 'buildSrc/unstripped.gradle' apply from: 'buildSrc/checkStyle.gradle' apply from: 'buildSrc/packageName.gradle' +apply from: 'buildSrc/download_jsc.gradle' version = project.hasProperty('weexVersion') ? project.getProperty('weexVersion') : '0.26.0.1' @@ -101,13 +102,15 @@ android { def android_project_dir = projectDir - def buildRuntimeApi = project.hasProperty('buildRuntimeApi') ? project.property('buildRuntimeApi') : false + def buildRuntimeApi = project.hasProperty('buildRuntimeApi') ? project.property('buildRuntimeApi').toBoolean() : false + def jsInterpolatorName = project.hasProperty('JSInterpolatorName') ? project.property('JSInterpolatorName') : 'JavaScriptCore' defaultPublishConfig project.useApachePackageName ? 'apacheRelease' : 'legacyRelease' defaultConfig { buildConfigField "String", "buildJavascriptFrameworkVersion", "\"${jsfmVersion}\"" buildConfigField "String", "buildVersion", "\"${version}\"" + buildConfigField "String", "JSInterpolatorName", "\"${jsInterpolatorName}\"" minSdkVersion project.minSdkVersion targetSdkVersion project.targetSdkVersion @@ -135,8 +138,10 @@ android { '-DANDROID_STL=' + "${cxx_stl}", '-DCMAKE_BUILD_TYPE=Release', '-DANDROID_PROJECT_DIR=' + "${android_project_dir}", - '-DENABLE_ASAN=false', - '-DBUILD_RUNTIME_API='+"${buildRuntimeApi}" + '-DENABLE_ASAN=false' + if(buildRuntimeApi){ + arguments '-DBUILD_RUNTIME_API='+"${buildRuntimeApi}" + } if(project.hasProperty('enableASan') && "true" == project.getProperty('enableASan')) { cppFlags "-fsanitize=address -fno-omit-frame-pointer" } @@ -273,4 +278,5 @@ task weex_core_license(type: com.hierynomus.gradle.license.tasks.LicenseFormat) 'Source/include/JavaScriptCore/**/*.cpp']) } -preBuild.dependsOn copyAndRenameCppSourceFile, copyAndRenamePackage, copyManifest, copyProguard, copyASanLib, checkNdkVersion, licenseFormat \ No newline at end of file +preBuild.dependsOn copyAndRenameCppSourceFile, copyAndRenamePackage, copyManifest, copyProguard, + copyASanLib, checkNdkVersion, licenseFormat, copyJscToJniDir \ No newline at end of file diff --git a/android/sdk/buildSrc/download_jsc.gradle b/android/sdk/buildSrc/download_jsc.gradle new file mode 100644 index 0000000..904d348 --- /dev/null +++ b/android/sdk/buildSrc/download_jsc.gradle @@ -0,0 +1,46 @@ +def jsc_dir = new File(project.buildDir, 'jsc') +def jsc_file = new File(jsc_dir, 'jsc.tgz') +def jsc_url = new URL('https://registry.npmjs.org/jsc-android/-/jsc-android-241213.1.0.tgz') +def aar_name = 'android-jsc-intl' + +def downloadJSC = { URL url, File dest -> + if (!dest.getParentFile().exists()) { + dest.getParentFile().mkdis() + } + url.withInputStream { i -> dest.withOutputStream { it << i } } +} + +task(download){ + doLast{ + if(!jsc_file.exists()) { + downloadJSC(jsc_url, jsc_file) + } + } +} + +task unzipJSC(type: Copy, dependsOn: download) { + from tarTree(resources.gzip(jsc_file)) + into jsc_dir + include "**/${aar_name}/**/*.aar" + eachFile{ + it.path = it.name + } + rename ".*", "${aar_name}.aar" +} + +task copyJscToJniDir(type: Copy, dependsOn: unzipJSC) { + if(project.hasProperty('jsc_url')){ + jsc_url = ext.getProperty('jsc_url').toString() + } + if(project.hasProperty('aar_name')){ + aar_name = ext.getProperty('aar_name').toString() + } + from zipTree(new File(jsc_dir, "${aar_name}.aar")) + into project.android.sourceSets.main.jniLibs.srcDirs[-1] + include 'jni/**/*.so' + eachFile{ + def path_list = new LinkedList<>(it.relativePath.segments.toList()) + path_list.removeAt(0) + it.relativePath = new RelativePath(true, path_list[0], path_list[1]) + } +} \ No newline at end of file diff --git a/android/sdk/buildSrc/packageName.gradle b/android/sdk/buildSrc/packageName.gradle index 345bb3d..d03cca7 100644 --- a/android/sdk/buildSrc/packageName.gradle +++ b/android/sdk/buildSrc/packageName.gradle @@ -1,8 +1,5 @@ task copyAndRenamePackage(type: Copy) { if(!project.useApachePackageName) { - doFirst { - delete new File('src/legacyRelease/java') - } from new File('src/main/java/org/apache/weex') into new File('src/legacyRelease/java/com/taobao/weex') filter { String line -> @@ -19,9 +16,6 @@ task copyAndRenamePackage(type: Copy) { task copyManifest(type: Copy){ if(!project.useApachePackageName){ - doFirst { - delete new File('src/legacyRelease/AndroidManifest.xml') - } from new File('src/main/AndroidManifest.xml') into new File('src/legacyRelease') filter { String line -> @@ -34,9 +28,6 @@ task copyManifest(type: Copy){ task copyProguard(type: Copy){ if(!project.useApachePackageName){ - doFirst { - delete new File('proguard-rules-legacy.pro') - } from new File('proguard-rules.pro') into new File('.') rename 'proguard-rules.pro', 'proguard-rules-legacy.pro' @@ -50,9 +41,6 @@ task copyProguard(type: Copy){ task copyOtherCppFile(type: Copy){ if(!project.useApachePackageName) { - doFirst { - delete new File('src/legacyRelease/cpp') - } from new File('../../weex_core') into new File('src/legacyRelease/cpp') exclude '**/*.cpp', '**/*.cc', '**/*.c', '**/*.h', '**/*.hpp' diff --git a/android/sdk/src/main/java/org/apache/weex/InitConfig.java b/android/sdk/src/main/java/org/apache/weex/InitConfig.java index 911271b..b6e3d4b 100644 --- a/android/sdk/src/main/java/org/apache/weex/InitConfig.java +++ b/android/sdk/src/main/java/org/apache/weex/InitConfig.java @@ -19,6 +19,8 @@ package org.apache.weex; import android.support.annotation.NonNull; +import java.util.LinkedList; +import java.util.List; import org.apache.weex.adapter.ClassLoaderAdapter; import org.apache.weex.adapter.IDrawableLoader; import org.apache.weex.adapter.IWXHttpAdapter; @@ -32,8 +34,6 @@ import org.apache.weex.adapter.URIAdapter; import org.apache.weex.appfram.storage.IWXStorageAdapter; import org.apache.weex.appfram.websocket.IWebSocketAdapterFactory; import org.apache.weex.performance.IApmGenerator; -import java.util.LinkedList; -import java.util.List; /** * Created by sospartan on 5/31/16. @@ -53,6 +53,8 @@ public class InitConfig { private IApmGenerator apmGenerater; private IWXJsFileLoaderAdapter jsFileLoaderAdapter; private IWXJscProcessManager jscProcessManager; + private String jsInterpolatorName; + private boolean useRuntimeAPI; private List<String> nativeLibraryList; public IWXHttpAdapter getHttpAdapter() { @@ -122,6 +124,14 @@ public class InitConfig { return nativeLibraryList; } + public String getJsInterpolatorName(){ + return jsInterpolatorName; + } + + public boolean isUseRuntimeAPI(){ + return useRuntimeAPI; + } + private InitConfig() { } @@ -135,6 +145,8 @@ public class InitConfig { URIAdapter mURIAdapter; IWXJSExceptionAdapter mJSExceptionAdapter; String framework; + String jsInterpolatorName = BuildConfig.JSInterpolatorName; + boolean useRuntimeAPI = false; IWebSocketAdapterFactory webSocketAdapterFactory; ClassLoaderAdapter classLoaderAdapter; IApmGenerator apmGenerater; @@ -226,6 +238,16 @@ public class InitConfig { return this; } + public Builder setJsInterpolatorName(String name){ + jsInterpolatorName = name; + return this; + } + + public Builder setUseRuntimeAPI(boolean useRuntimeAPI){ + this.useRuntimeAPI = useRuntimeAPI; + return this; + } + public InitConfig build(){ InitConfig config = new InitConfig(); config.httpAdapter = this.httpAdapter; @@ -243,6 +265,8 @@ public class InitConfig { config.jsFileLoaderAdapter = this.jsFileLoaderAdapter; config.jscProcessManager = this.jscProcessManager; config.nativeLibraryList = this.nativeLibraryList; + config.jsInterpolatorName = this.jsInterpolatorName; + config.useRuntimeAPI = this.useRuntimeAPI; return config; } } diff --git a/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java b/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java index d1d87fa..b713dbe 100644 --- a/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java +++ b/android/sdk/src/main/java/org/apache/weex/WXEnvironment.java @@ -29,18 +29,10 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.Typeface; import android.os.Environment; +import android.support.annotation.RestrictTo; +import android.support.annotation.RestrictTo.Scope; import android.telephony.TelephonyManager; import android.text.TextUtils; -import org.apache.weex.R; -import org.apache.weex.common.WXConfig; -import org.apache.weex.utils.FontDO; -import org.apache.weex.utils.LogLevel; -import org.apache.weex.utils.TypefaceUtil; -import org.apache.weex.utils.WXFileUtils; -import org.apache.weex.utils.WXLogUtils; -import org.apache.weex.utils.WXSoInstallMgrSdk; -import org.apache.weex.utils.WXUtils; -import org.apache.weex.utils.WXViewUtils; import dalvik.system.PathClassLoader; import java.io.BufferedReader; import java.io.File; @@ -52,6 +44,16 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.weex.R; +import org.apache.weex.common.WXConfig; +import org.apache.weex.utils.FontDO; +import org.apache.weex.utils.LogLevel; +import org.apache.weex.utils.TypefaceUtil; +import org.apache.weex.utils.WXFileUtils; +import org.apache.weex.utils.WXLogUtils; +import org.apache.weex.utils.WXSoInstallMgrSdk; +import org.apache.weex.utils.WXUtils; +import org.apache.weex.utils.WXViewUtils; public class WXEnvironment { @@ -93,7 +95,8 @@ public class WXEnvironment { public static boolean AUTO_UPDATE_APPLICATION_SCREEN_SIZE = true; - public static volatile boolean sUseRunTimeApi = false; + @RestrictTo(Scope.LIBRARY) + public static volatile boolean sUseRunTimeApi; /** * Debug model @@ -137,7 +140,9 @@ public class WXEnvironment { public static final String CORE_JSS_SO_NAME = "weexjss"; public static final String CORE_JSB_SO_NAME = "weexjsb"; public static final String CORE_JST_SO_NAME = "weexjst"; - public static final String CORE_JSC_SO_NAME = "JavaScriptCore"; + + @RestrictTo(Scope.LIBRARY) + public static String CORE_JSC_SO_NAME = BuildConfig.JSInterpolatorName; private static String CORE_JSS_SO_PATH = null; public static String CORE_JSS_RUNTIME_SO_PATH = null; diff --git a/android/sdk/src/main/java/org/apache/weex/WXSDKEngine.java b/android/sdk/src/main/java/org/apache/weex/WXSDKEngine.java index ed1cda6..97799d5 100644 --- a/android/sdk/src/main/java/org/apache/weex/WXSDKEngine.java +++ b/android/sdk/src/main/java/org/apache/weex/WXSDKEngine.java @@ -196,6 +196,8 @@ public class WXSDKEngine implements Serializable { } private static void doInitInternal(final Application application,final InitConfig config){ + WXEnvironment.sUseRunTimeApi = config.isUseRuntimeAPI(); + WXEnvironment.CORE_JSC_SO_NAME = config.getJsInterpolatorName(); WXEnvironment.sApplication = application; if(application == null){ WXLogUtils.e(TAG, " doInitInternal application is null"); diff --git a/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java b/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java index a81c7ba..838cc04 100644 --- a/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java +++ b/android/sdk/src/main/java/org/apache/weex/utils/WXFileUtils.java @@ -36,9 +36,11 @@ import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Locale; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; +import org.apache.weex.WXEnvironment; public class WXFileUtils { @@ -212,7 +214,8 @@ public class WXFileUtils { continue; } if(zipEntry.getName().contains("lib/armeabi/") && - (zipEntry.getName().contains("weex") || zipEntry.getName().equals("libJavaScriptCore.so"))){ + (zipEntry.getName().contains("weex") || zipEntry.getName().equals( + String.format(Locale.ENGLISH, "lib%s.so", WXEnvironment.CORE_JSC_SO_NAME)))){ String[] fileNames = zipEntry.getName().split("/"); String fileName = fileNames[fileNames.length - 1]; InputStream inputStream = zip.getInputStream(zipEntry); diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt index d1bb5fe..a412f8b 100755 --- a/weex_core/Source/CMakeLists.txt +++ b/weex_core/Source/CMakeLists.txt @@ -119,19 +119,14 @@ if(ANDROID) ## add_subdirectory for subdirectory has a CMakeLists.txt add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/IPC) - - message("check build jsc BUILD_RUNTIME_API flag: ${BUILD_RUNTIME_API}") - if ("${BUILD_RUNTIME_API}" STREQUAL "true") - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/js_runtime) - message("cmake build jsApi for runtime") + if (DEFINED BUILD_RUNTIME_API) + message("Variable BUILD_RUNTIME_API is defined with value: ${BUILD_RUNTIME_API}") + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/js_runtime) else() - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android/jsengine) - message("cmake build jsApi for jsc") + message("Variable BUILD_RUNTIME_API is not defined") + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android/jsengine) endif() - - - ## include_directories for include head file include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/IPC) diff --git a/weex_core/Source/js_runtime/CMakeLists.txt b/weex_core/Source/js_runtime/CMakeLists.txt index 42bd160..51f8e6d 100644 --- a/weex_core/Source/js_runtime/CMakeLists.txt +++ b/weex_core/Source/js_runtime/CMakeLists.txt @@ -212,10 +212,6 @@ set(${WEEXJSSERVER_NAME}_LIBRARIES weexbase weexipc wson -#c++_shared -JavaScriptCore -WTF -#jsc log z -lc @@ -223,6 +219,20 @@ z -pthread ) +if (DEFINED BUILD_RUNTIME_API) + set(${WEEXJSSERVER_NAME}_LIBRARIES + ${${WEEXJSSERVER_NAME}_LIBRARIES} + c++_shared + jsc + ) +else() + set(${WEEXJSSERVER_NAME}_LIBRARIES + ${${WEEXJSSERVER_NAME}_LIBRARIES} + JavaScriptCore + WTF + ) +endif() + add_library(${WEEXJSSERVER_NAME} SHARED ${${WEEXJSSERVER_NAME}_SOURCES} ) diff --git a/weex_core/Source/js_runtime/weex/utils/weex_jsc_utils.h b/weex_core/Source/js_runtime/weex/utils/weex_jsc_utils.h index 30a87d8..b46945d 100644 --- a/weex_core/Source/js_runtime/weex/utils/weex_jsc_utils.h +++ b/weex_core/Source/js_runtime/weex/utils/weex_jsc_utils.h @@ -209,6 +209,7 @@ namespace WEEXICU { // } static bool initICUEnv(bool multiProcess) { + #ifdef BUILD_RUNTIME_API static bool isInit = false; if (isInit) return true; @@ -245,6 +246,9 @@ namespace WEEXICU { return true;//mapIcuData(std::string(path)); } return false; + #else + return true; + #endif } } diff --git a/weex_core/Source/libs/arm64-v8a/libJavaScriptCore.so b/weex_core/Source/libs/arm64-v8a/libJavaScriptCore.so deleted file mode 100755 index 56307f0..0000000 Binary files a/weex_core/Source/libs/arm64-v8a/libJavaScriptCore.so and /dev/null differ diff --git a/weex_core/Source/libs/arm64-v8a/libWTF.so b/weex_core/Source/libs/arm64-v8a/libWTF.so deleted file mode 100755 index ce8d0bc..0000000 Binary files a/weex_core/Source/libs/arm64-v8a/libWTF.so and /dev/null differ diff --git a/weex_core/Source/libs/armeabi-v7a/libJavaScriptCore.so b/weex_core/Source/libs/armeabi-v7a/libJavaScriptCore.so deleted file mode 100755 index 2d59099..0000000 Binary files a/weex_core/Source/libs/armeabi-v7a/libJavaScriptCore.so and /dev/null differ diff --git a/weex_core/Source/libs/armeabi-v7a/libWTF.so b/weex_core/Source/libs/armeabi-v7a/libWTF.so deleted file mode 100755 index 790bef2..0000000 Binary files a/weex_core/Source/libs/armeabi-v7a/libWTF.so and /dev/null differ diff --git a/weex_core/Source/libs/armeabi/libJavaScriptCore.so b/weex_core/Source/libs/armeabi/libJavaScriptCore.so deleted file mode 100755 index 2d59099..0000000 Binary files a/weex_core/Source/libs/armeabi/libJavaScriptCore.so and /dev/null differ diff --git a/weex_core/Source/libs/armeabi/libWTF.so b/weex_core/Source/libs/armeabi/libWTF.so deleted file mode 100755 index 790bef2..0000000 Binary files a/weex_core/Source/libs/armeabi/libWTF.so and /dev/null differ diff --git a/weex_core/Source/libs/x86/libJavaScriptCore.so b/weex_core/Source/libs/x86/libJavaScriptCore.so deleted file mode 100755 index b7abc27..0000000 Binary files a/weex_core/Source/libs/x86/libJavaScriptCore.so and /dev/null differ diff --git a/weex_core/Source/libs/x86/libWTF.so b/weex_core/Source/libs/x86/libWTF.so deleted file mode 100755 index 0f4c2df..0000000 Binary files a/weex_core/Source/libs/x86/libWTF.so and /dev/null differ