0. 准备工作
获取源码:git clone https://common-lisp.net/project/ecl/
准备Android SDK 及 NDK (NDK要求r17c版本,可以访问 https://developer.android.google.cn/ndk/downloads/older_releases.html 找到)
安装32位的glibc
1. 构建主机 ECL
./configure ABI= 32 CFLAGS= "-m32 -g -O2" LDFLAGS= "-m32 -g -O2" \
--prefix= ` pwd ` /ecl-android-host --disable-c99complex
make -j9
make install
rm -r build
export ECL_TO_RUN= ` pwd ` /ecl-android-host/bin/ecl
2. 配置工具链并导出必要路径
export NDK_PATH= /opt/android-ndk
export ANDROID_API= 23
export TOOLCHAIN_PATH= ` pwd ` /android-toolchain
${NDK_PATH} /build/tools/make_standalone_toolchain.py --arch arm --install-dir ${TOOLCHAIN_PATH} --api ${ANDROID_API}
export SYSROOT= ${TOOLCHAIN_PATH} /sysroot
export PATH= ${TOOLCHAIN_PATH} /bin:$PATH
3. 编译并安装必要的库
export LDFLAGS= "--sysroot=${SYSROOT} -D__ANDROID_API__=${ANDROID_API} -fuse-ld=bfd"
export CPPFLAGS= "--sysroot=${SYSROOT} -D__ANDROID_API__=${ANDROID_API} -isystem ${SYSROOT} /usr/include/arm-linux-androideabi"
export CC= arm-linux-androideabi-clang
./configure --host= arm-linux-androideabi \
--prefix= ` pwd ` /ecl-android \
--disable-c99complex \
--with-cross-config= ` pwd ` /src/util/android-arm.cross_config
make -j9
make install
4. 建立Android项目
使用Android Studio 创建项目,包名为 org.lisp.ecl (根据实际情况更改)。
添加 JNI目录和 CMakeLists.txt 文件,内容如下:cmake_minimum_required(VERSION 3.4.1)
set(ECL_HOME /home/skyline/workspace/collection/ecl/ecl-android) #根据实际情况修改
include_directories(${ECL_HOME}/include)
link_directories(${ECL_HOME}/lib)
add_library(ecl
SHARED
IMPORTED)
set_target_properties(ecl
PROPERTIES IMPORTED_LOCATION
${ECL_HOME}/lib/libecl.so)
add_library(
ecl-android
SHARED
src/main/jni/org_lisp_ecl_EmbeddedCommonLisp.c
src/main/jni/ecl_boot.c)
find_library(log-lib
log)
target_link_libraries(ecl-android
ecl
${log-lib})
将上一步编译出来的目录 ecl-android/lib 下的 libecl.so 复制到工程app/libs/armeabi-v7a下。
将ECL项目中 examples/android 下的资源、代码添加到自己工程中。
app/build.gradle 添加相应配置,例如:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "org.lisp.ecl"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
ndk {
//设置支持的SO库架构
abiFilters "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jni.srcDirs = ['src/main/jni', 'src/main/jni/']
jniLibs.srcDirs = ['libs']
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}