Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [Android] Remove shared library from binary of Weex (#2940)
Browse files Browse the repository at this point in the history
* [Android] Make JS Interpolator in Android as replaceable.

* [Android] support switch javascriptCore (legacy)or jsc (apache)

* [Android] fix

* [Android] Revert the commit of initConfig.
  • Loading branch information
YorkShen authored and lucky-chen committed Oct 11, 2019
1 parent bf02df0 commit 739e07f
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 58 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ script:
if npm run danger -- ci --dangerfile ./dangerfile-android.js | grep -q "hasAndroidFile" ; then
cd android
./gradlew clean assembleRelease --quiet -PbuildRuntimeApi=true ${GRADLE_ABI} -PapachePackageName="false" || exit 1
./gradlew assembleRelease --quiet -PbuildRuntimeApi=false ${GRADLE_ABI} -PapachePackageName="false" || exit 1
./gradlew :weex_sdk:assembleRelease --quiet -PbuildRuntimeApi=true ${GRADLE_ABI} -PapachePackageName="true" || exit 1
./gradlew :weex_sdk:assembleRelease --quiet -PbuildRuntimeApi=false ${GRADLE_ABI} -PapachePackageName="true" || exit 1
./gradlew assembleRelease --quiet ${GRADLE_ABI} -PbuildRuntimeApi=false -Pjsc_url="https://github.com/raw/apache/incubator-weex/release/0.26/android/sdk/weex_sdk-0.26.0.aar" -Paar_name="weex_sdk" -PJSInterpolatorName="JavaScriptCore" -PapachePackageName="false" || exit 1
./gradlew :weex_sdk:assembleRelease --quiet -PbuildRuntimeApi=true ${GRADLE_ABI} -PapachePackageName="true" || exit 1
./gradlew :weex_sdk:assembleRelease --quiet ${GRADLE_ABI} -PbuildRuntimeApi=false -Pjsc_url="https://github.com/raw/apache/incubator-weex/release/0.26/android/sdk/weex_sdk-0.26.0.aar" -Paar_name="weex_sdk" -PJSInterpolatorName="JavaScriptCore" -PapachePackageName="true" || exit 1
fi
;;
"jsfm" )
Expand Down
3 changes: 2 additions & 1 deletion android/sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ assets/weex-main-jsfm.js
assets/weex-rax-api.js
.externalNativeBuild

/libs/armeabi
/libs/
/src/main/jniLibs

/src/legacyRelease/
proguard-rules-legacy.pro
22 changes: 17 additions & 5 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -101,13 +102,19 @@ android {

def android_project_dir = projectDir

def buildRuntimeApi = project.hasProperty('buildRuntimeApi') ? project.property('buildRuntimeApi') : false
def buildRuntimeApi = project.hasProperty('buildRuntimeApi') ? project.property('buildRuntimeApi').toBoolean() : true
def jsInterpolatorName = project.hasProperty('JSInterpolatorName') ? project.property('JSInterpolatorName') : 'jsc'
def initJSCPrivateApi = false
if (buildRuntimeApi){
initJSCPrivateApi = 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

Expand Down Expand Up @@ -135,8 +142,13 @@ 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 (initJSCPrivateApi){
arguments '-DINIT_JSC_PRIVATE_API='+"${initJSCPrivateApi}"
}
}
if(project.hasProperty('enableASan') && "true" == project.getProperty('enableASan')) {
cppFlags "-fsanitize=address -fno-omit-frame-pointer"
}
Expand Down Expand Up @@ -189,7 +201,6 @@ android {

sourceSets {
main.assets.srcDirs = ['assets']
main.jniLibs.srcDirs = ['libs']
apacheRelease.java.srcDirs = ['src/main/java']
apacheRelease.manifest.srcFile(new File('src/main/AndroidManifest.xml'))
legacyRelease.java.srcDirs = ['src/legacyRelease/java']
Expand Down Expand Up @@ -273,4 +284,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
preBuild.dependsOn copyAndRenameCppSourceFile, copyAndRenamePackage, copyManifest, copyProguard,
copyASanLib, checkNdkVersion, licenseFormat, copyJscToJniDir
57 changes: 57 additions & 0 deletions android/sdk/buildSrc/download_jsc.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
def jsc_dir = new File(project.buildDir, 'jsc')
def jsc_url = project.hasProperty('jsc_url') ? new URL(project.getProperty('jsc_url').toString()) : new URL('https://registry.npmjs.org/jsc-android/-/jsc-android-241213.1.0.tgz')
def aar_name = project.hasProperty('aar_name') ? project.getProperty('aar_name').toString() : 'android-jsc-intl'

def jsc_file = new File(jsc_dir, jsc_url.path.split('/').last())
def aar_file = new File(jsc_dir, "${aar_name}.aar")

def downloadJSC = { URL url, File dest ->
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs()
}
url.withInputStream { i -> dest.withOutputStream { it << i } }
}

task download(){
inputs.property('url', jsc_url)
outputs.file(jsc_file)
doFirst {
if (!jsc_file.exists()) {
downloadJSC(jsc_url, jsc_file)
}
}
}

task unzipJSC(type: Copy, dependsOn: download) {
from jsc_file.name.endsWith(".aar") ? jsc_file : tarTree(jsc_file)
into jsc_dir
include "**/*${aar_name}*.aar"
includeEmptyDirs false
eachFile {
it.path = it.name
it.name = "${aar_name}.aar"
}
inputs.file(jsc_file)
outputs.file(aar_file)
}

task copyJscToJniDir(type: Copy, dependsOn: unzipJSC) {
def libsDir = project.android.sourceSets.main.jniLibs.srcDirs[-1]
doFirst{
delete libsDir
}
from zipTree(aar_file)
into libsDir
include 'jni/**/*.so'
exclude '**/libweexcore.so', '**/libweexjsb.so', '**/libweexjss.so',
'**/libweexjssr.so', '**/libweexjst.so', '**/libc++_shared.so',
'**/x86_64/**'
includeEmptyDirs false
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])
}
inputs.file(aar_file)
outputs.dir(libsDir)
}
12 changes: 0 additions & 12 deletions android/sdk/buildSrc/packageName.gradle
Original file line number Diff line number Diff line change
@@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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'
Expand All @@ -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'
Expand Down
Binary file removed android/sdk/libs/arm64-v8a/libJavaScriptCore.so
Binary file not shown.
Binary file removed android/sdk/libs/arm64-v8a/libWTF.so
Binary file not shown.
Binary file removed android/sdk/libs/armeabi-v7a/libJavaScriptCore.so
Binary file not shown.
Binary file removed android/sdk/libs/armeabi-v7a/libWTF.so
Binary file not shown.
Binary file removed android/sdk/libs/x86/libJavaScriptCore.so
Binary file not shown.
Binary file removed android/sdk/libs/x86/libWTF.so
Binary file not shown.
36 changes: 17 additions & 19 deletions android/sdk/src/main/java/org/apache/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@
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;
Expand All @@ -52,6 +44,16 @@
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 {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -137,10 +140,10 @@ 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";
private static String CORE_JSS_SO_PATH = null;

public static String CORE_JSS_RUNTIME_SO_PATH = null;
@RestrictTo(Scope.LIBRARY)
public static String CORE_JSC_SO_NAME = BuildConfig.JSInterpolatorName;
public static String CORE_JSS_SO_PATH = null;

private static String CORE_JSS_ICU_PATH = null;

Expand Down Expand Up @@ -607,11 +610,6 @@ public static String getLibJScRealPath() {
}

public static String getLibJssRealPath() {
if (WXEnvironment.sUseRunTimeApi && !TextUtils.isEmpty(CORE_JSS_RUNTIME_SO_PATH)){
WXLogUtils.d("test-> findLibJssRuntimeRealPath " + CORE_JSS_RUNTIME_SO_PATH);
return CORE_JSS_RUNTIME_SO_PATH;
}

if(TextUtils.isEmpty(CORE_JSS_SO_PATH)) {
CORE_JSS_SO_PATH = findSoPath(CORE_JSS_SO_NAME);
WXLogUtils.d("test-> findLibJssRealPath " + CORE_JSS_SO_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
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 {

Expand Down Expand Up @@ -212,7 +214,8 @@ public static void extractSo(String apkFile, String path) throws IOException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public static void copyJssRuntimeSo(){
if (!TextUtils.equals(WXEnvironment.getAppVersionName(),defaultSettingValue)){
targetFile.delete();
}else {
WXEnvironment.CORE_JSS_RUNTIME_SO_PATH= targetFile.getAbsolutePath();
WXEnvironment.CORE_JSS_SO_PATH= targetFile.getAbsolutePath();
WXEnvironment.sUseRunTimeApi = true;
WXLogUtils.e("weex", "copyJssRuntimeSo exist: return");
return;
Expand All @@ -321,7 +321,7 @@ public static void copyJssRuntimeSo(){
targetFile.createNewFile();
WXFileUtils.copyFileWithException(new File(fromPath),targetFile);
/**3. update flag **/
WXEnvironment.CORE_JSS_RUNTIME_SO_PATH= targetFile.getAbsolutePath();
WXEnvironment.CORE_JSS_SO_PATH= targetFile.getAbsolutePath();
WXEnvironment.writeDefaultSettingsValue(keyVersionCode,WXEnvironment.getAppVersionName());
WXEnvironment.sUseRunTimeApi = true;
WXLogUtils.e("weex", "copyJssRuntimeSo: cp end and return ");
Expand Down
17 changes: 6 additions & 11 deletions weex_core/Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_definitions(-DDOM_PARSER_LOG=0)
add_definitions(-DDEBUG=1)

message("ANDROID_PROJECT_DIR:"${ANDROID_PROJECT_DIR})
set(LOCAL_LIBRARIES_DIR ${ANDROID_PROJECT_DIR}/libs/${ANDROID_ABI})
set(LOCAL_LIBRARIES_DIR ${ANDROID_PROJECT_DIR}/src/main/jniLibs/${ANDROID_ABI})

if ("${ANDROID_ABI}" STREQUAL "x86")
# todo
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 14 additions & 4 deletions weex_core/Source/js_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,27 @@ set(${WEEXJSSERVER_NAME}_LIBRARIES
weexbase
weexipc
wson
#c++_shared
JavaScriptCore
WTF
#jsc
log
z
-lc
-ldl
-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} )

Expand Down
5 changes: 5 additions & 0 deletions weex_core/Source/js_runtime/weex/utils/weex_jsc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ namespace WEEXICU {
// }

static bool initICUEnv(bool multiProcess) {
#ifdef INIT_JSC_PRIVATE_API
static bool isInit = false;
if (isInit)
return true;
Expand Down Expand Up @@ -245,6 +246,10 @@ namespace WEEXICU {
return true;//mapIcuData(std::string(path));
}
return false;
#else
LOGE("skip initICUEnv");
return true;
#endif
}

}
Expand Down
Binary file removed weex_core/Source/libs/arm64-v8a/libJavaScriptCore.so
Binary file not shown.
Binary file removed weex_core/Source/libs/arm64-v8a/libWTF.so
Binary file not shown.
Binary file not shown.
Binary file removed weex_core/Source/libs/armeabi-v7a/libWTF.so
Binary file not shown.
Binary file removed weex_core/Source/libs/armeabi/libJavaScriptCore.so
Binary file not shown.
Binary file removed weex_core/Source/libs/armeabi/libWTF.so
Binary file not shown.
Binary file removed weex_core/Source/libs/x86/libJavaScriptCore.so
Binary file not shown.
Binary file removed weex_core/Source/libs/x86/libWTF.so
Binary file not shown.

0 comments on commit 739e07f

Please sign in to comment.