Skip to content

Commit

Permalink
🐞 fix: Change .so to .so.android for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Sep 2, 2024
1 parent 418a030 commit 20334d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ replay_pid*
rust/target
*.dll
*.so
*.so.android
*.dylib

# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion scripts/ts/copy_swc4j_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const OS_CONFIG_MAP = {
'android': {
sourceName: `lib${NAME}`,
targetName: `lib${NAME}`,
ext: '.so',
ext: '.so.android',
targets: {
'x86': 'i686-linux-android',
'x86_64': 'x86_64-linux-android',
Expand Down
29 changes: 8 additions & 21 deletions src/main/java/com/caoccao/javet/swc4j/Swc4jLibLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.caoccao.javet.swc4j.interfaces.ISwc4jLogger;
import com.caoccao.javet.swc4j.utils.ArrayUtils;
import com.caoccao.javet.swc4j.utils.OSUtils;
import com.caoccao.javet.swc4j.utils.StringUtils;
import com.caoccao.javet.swc4j.utils.Swc4jDefaultLogger;

import java.io.File;
Expand All @@ -44,13 +43,11 @@ final class Swc4jLibLoader {
private static final String ARCH_X86_64 = "x86_64";
private static final int BUFFER_LENGTH = 4096;
private static final String CHMOD = "chmod";
private static final String LIB_FILE_EXTENSION_ANDROID = "so";
private static final String LIB_FILE_EXTENSION_ANDROID = "so.android";
private static final String LIB_FILE_EXTENSION_LINUX = "so";
private static final String LIB_FILE_EXTENSION_MACOS = "dylib";
private static final String LIB_FILE_EXTENSION_WINDOWS = "dll";
private static final String LIB_FILE_NAME_FORMAT = "libswc4j-{0}-{1}.v.{2}.{3}";
private static final String LIB_FILE_NAME_FOR_ANDROID_FORMAT = "libswc4j-{0}.v.{1}.{2}";
private static final String LIB_FILE_NAME_PREFIX = "lib";
private static final String LIB_NAME = "swc4j";
private static final String LIB_VERSION = "1.0.0";
private static final ISwc4jLogger LOGGER = new Swc4jDefaultLogger(Swc4jLibLoader.class.getName());
Expand Down Expand Up @@ -144,20 +141,12 @@ private String getLibFileName() throws Swc4jLibException {
if (osArch == null) {
throw Swc4jLibException.archNotSupported(OSUtils.OS_ARCH);
}
if (OSUtils.IS_ANDROID) {
return MessageFormat.format(
LIB_FILE_NAME_FOR_ANDROID_FORMAT,
osName,
LIB_VERSION,
fileExtension);
} else {
return MessageFormat.format(
LIB_FILE_NAME_FORMAT,
osName,
osArch,
LIB_VERSION,
fileExtension);
}
return MessageFormat.format(
LIB_FILE_NAME_FORMAT,
osName,
osArch,
LIB_VERSION,
fileExtension);
}

private String getOSArch() {
Expand Down Expand Up @@ -195,9 +184,7 @@ private String getOSName() {
}

private String getResourceFileName() throws Swc4jLibException {
String resourceFileName = MessageFormat.format(RESOURCE_NAME_FORMAT, OSUtils.IS_ANDROID
? StringUtils.join("/", LIB_FILE_NAME_PREFIX, getAndroidABI(), getLibFileName())
: getLibFileName());
String resourceFileName = MessageFormat.format(RESOURCE_NAME_FORMAT, getLibFileName());
if (Swc4jNative.class.getResource(resourceFileName) == null) {
throw Swc4jLibException.libNotFound(resourceFileName);
}
Expand Down

0 comments on commit 20334d3

Please sign in to comment.