-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
238 changed files
with
24,605 additions
and
1,525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cmake-build-debug | ||
.DS_Store | ||
build_switch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Log/OS Files | ||
*.log | ||
|
||
# Android Studio generated files and folders | ||
captures/ | ||
.externalNativeBuild/ | ||
.cxx/ | ||
*.apk | ||
output.json | ||
|
||
# IntelliJ | ||
*.iml | ||
.idea/ | ||
misc.xml | ||
deploymentTargetDropDown.xml | ||
render.experimental.xml | ||
|
||
# Keystore files | ||
*.jks | ||
*.keystore | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
google-services.json | ||
|
||
# Android Profiling | ||
*.hprof | ||
|
||
# libromfs generator | ||
libromfs-generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# borealis android demo | ||
|
||
[中文](./README_ZH.md) | ||
|
||
The Android port of borealis follows SDL's documentation: [SDL/docs](https://github.com/libsdl-org/SDL/blob/release-2.28.x/docs/README-android.md) | ||
|
||
Currently, this project uses SDL 2.28.*, but there are some interesting Android-specific features in SDL3. We plan to migrate to SDL3 once it is officially released. | ||
|
||
Theoretically, it supports Android API 16 and later (Android 4.1+), but I have only tested it on devices running Android 5.0+ because I couldn't find older devices. | ||
|
||
## Building | ||
|
||
```shell | ||
cd android-project | ||
``` | ||
|
||
On the Android platform, borealis uses libromfs to package all resource files directly into the shared library. We need to build the libromfs-generator first. | ||
|
||
> The libromfs-generator is responsible for converting resource files into C++ source code and linking them into the main program during the compilation process. | ||
```shell | ||
./build_libromfs_generator.sh | ||
``` | ||
|
||
After a successful run, `libromfs-generator` will be generated in the `app/jni` directory. | ||
|
||
Then open Android Studio and build the project. | ||
|
||
```shell | ||
# macOS: compile and install from the command line | ||
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home | ||
export ANDROID_SDK_ROOT=~/Library/Android/sdk | ||
# Once built, the APK will be located in the app/build/outputs/apk/debug directory by default | ||
./gradlew assembleDebug | ||
# Directly install the APK (requires the device or emulator to be connected via adb) | ||
./gradlew installDebug | ||
``` | ||
|
||
## Migrating your borealis project to Android | ||
|
||
1. Place your project under the `app/jni` directory. | ||
2. Modify `app/jni/CMakeLists.txt` and replace the relevant parts of borealis with your project. | ||
3. Modify the `applicationId` in `app/build.gradle` and change it to your package name. | ||
4. Create your own activity by imitating `com.borealis.demo` in `app/src/main/java`. | ||
5. Modify `app/src/main/AndroidManifest.xml` and change the package to your package name, and change `DemoActivity` to the name of your created activity. | ||
6. Modify the app name in `app/src/main/res/values/strings.xml`. | ||
7. Replace `app/src/main/res/mipmap-*/ic_launcher.png` with your application icon. | ||
|
||
You can refer to the early commit history of this project to get an idea of what needs to be modified. | ||
|
||
## Known Issues | ||
|
||
If you delete some resource files, libromfs may not recognize it, causing a compilation error. In such cases, a temporary solution is to: | ||
|
||
Make a minor adjustment in `app/jni/CMakeLists.txt` (add an empty line), to trigger cmake to run again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# borealis android demo | ||
|
||
borealis 的安卓移植遵循 SDL 的文档:[SDL/docs](https://github.com/libsdl-org/SDL/blob/release-2.28.x/docs/README-android.md) | ||
|
||
目前本项目使用 SDL 2.28.* ,在 SDL3 中有一些关于安卓的有趣的特性,预计在其正式发布后再进行迁移 | ||
|
||
理论上支持 Android API 16 及之后机型 (Android 4.1+),但我只在 Android 5.0+ 的设备上测试过,因为我实在找不到更老的设备了。 | ||
|
||
## 构建 | ||
|
||
```shell | ||
cd android-project | ||
``` | ||
|
||
在安卓平台,borealis 使用 libromfs 将所有资源文件直接打包到共享库中,我们需要先构建 libromfs-generator。 | ||
|
||
> libromfs-generator 的作用是将资源文件转换为 cpp 源码,并在后续的编译过程中链接进主程序, | ||
```shell | ||
./build_libromfs_generator.sh | ||
``` | ||
|
||
在成功运行后,`app/jni` 目录下会生成: `libromfs-generator` | ||
|
||
然后打开 Android Studio 编译即可 | ||
|
||
```shell | ||
# 在 mac 下我使用这样的命令以从命令行编译和安装 | ||
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home | ||
export ANDROID_SDK_ROOT=~/Library/Android/sdk | ||
# 构建好之后,apk 默认会在 app/build/outputs/apk/debug 目录下 | ||
./gradlew assembleDebug | ||
# 直接进行安装 (需要手机或模拟器已经通过 adb 连接) | ||
./gradlew installDebug | ||
``` | ||
|
||
## 如何让你的 borealis 项目迁移到安卓 | ||
|
||
1. 将你的项目放置在 app/jni 目录下 | ||
2. 修改 app/jni/CMakeLists.txt 把原本 borealis 的部分替换成你的项目 | ||
3. 修改 app/build.gradle 中的 applicationId,把它改为你的包名 | ||
4. 模仿 app/src/main/java 下的 com.borealis.demo 创建你的 Activity | ||
5. 修改 app/src/main/AndroidMainifest.xml,将 package 改为你的包名,将DemoActivity改为你创建的 Activity 名 | ||
6. 修改 app/src/main/res/values/strings.xml 中的软件名 | ||
7. 修改 app/src/main/res/mipmap-*/ic_launcher.png 为你的应用图标 | ||
|
||
你可以查阅这个项目的早期提交记录来获得需要修改的内容大概范围 | ||
|
||
## 存在的问题 | ||
|
||
如果删除了某些资源文件,libromfs 可能没有识别出来,导致编译报错,这时候临时的解决方法是: | ||
|
||
微调一下 app/jni/CMakeLists.txt (随意加一空行即可),以触发 cmake 重新运行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY'); | ||
def buildAsApplication = !buildAsLibrary | ||
if (buildAsApplication) { | ||
apply plugin: 'com.android.application' | ||
} | ||
else { | ||
apply plugin: 'com.android.library' | ||
} | ||
|
||
android { | ||
compileSdkVersion 31 | ||
defaultConfig { | ||
if (buildAsApplication) { | ||
applicationId "com.borealis.demo" | ||
} | ||
minSdkVersion 16 | ||
targetSdkVersion 31 | ||
versionCode 1 | ||
versionName "1.0" | ||
// borealis need at least ndk r22 (r21 don't have std::filesystem support) | ||
// The newer NDK library will cause lower versions of Android failed to run. | ||
// r26: support api21 and later | ||
// r24/r25: support api19 and later | ||
// r22/23: support api16 and later | ||
ndkVersion "22.1.7171670" | ||
externalNativeBuild { | ||
cmake { | ||
arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static" | ||
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' | ||
abiFilters 'armeabi-v7a', 'arm64-v8a' | ||
version = '3.16.0+' | ||
} | ||
} | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
applicationVariants.all { variant -> | ||
tasks["merge${variant.name.capitalize()}Assets"] | ||
.dependsOn("externalNativeBuild${variant.name.capitalize()}") | ||
} | ||
if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) { | ||
sourceSets.main { | ||
jniLibs.srcDir 'libs' | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path 'jni/CMakeLists.txt' | ||
version = '3.16.0+' | ||
} | ||
} | ||
|
||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
|
||
if (buildAsLibrary) { | ||
libraryVariants.all { variant -> | ||
variant.outputs.each { output -> | ||
def outputFile = output.outputFile | ||
if (outputFile != null && outputFile.name.endsWith(".aar")) { | ||
def fileName = "org.libsdl.app.aar"; | ||
output.outputFile = new File(outputFile.parent, fileName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(call all-subdir-makefiles) |
Oops, something went wrong.