0
0
mirror of https://github.com/florisboard/florisboard.git synced 2024-09-19 19:42:20 +02:00

Remove cpp native code from app

This commit is contained in:
Patrick Goldinger 2024-04-04 17:48:52 +02:00
parent c5e7fea8f2
commit c198e8b376
No known key found for this signature in database
GPG Key ID: 533467C3DC7B9262
8 changed files with 5 additions and 276 deletions

View File

@ -71,23 +71,6 @@ android {
arg("room.expandProjection", "true")
}
externalNativeBuild {
cmake {
targets("florisboard-native")
cppFlags("-std=c++20", "-stdlib=libc++")
arguments(
"-DCMAKE_ANDROID_API=" + minSdk.toString(),
"-DICU_ASSET_EXPORT_DIR=" + project.file("src/main/assets/icu4c").absolutePath,
"-DBUILD_SHARED_LIBS=false",
"-DANDROID_STL=c++_static",
)
}
}
ndk {
abiFilters += listOf("armeabi-v7a", "arm64-v8a")
}
sourceSets {
maybeCreate("main").apply {
assets {
@ -118,11 +101,11 @@ android {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
externalNativeBuild {
cmake {
path("src/main/cpp/CMakeLists.txt")
}
}
//externalNativeBuild {
// cmake {
// path("src/main/cpp/CMakeLists.txt")
// }
//}
buildTypes {
named("debug") {
@ -132,11 +115,6 @@ android {
isDebuggable = true
isJniDebuggable = false
ndk {
// For running FlorisBoard on the emulator
abiFilters += listOf("x86", "x86_64")
}
resValue("mipmap", "floris_app_icon", "@mipmap/ic_app_icon_debug")
resValue("mipmap", "floris_app_icon_round", "@mipmap/ic_app_icon_debug_round")
resValue("drawable", "floris_app_icon_foreground", "@drawable/ic_app_icon_debug_foreground")

View File

@ -1,29 +0,0 @@
cmake_minimum_required(VERSION 3.22)
project(florisboard)
set(CMAKE_CXX_STANDARD 20)
include_directories(.)
### FlorisBoard ###
add_subdirectory(utils)
add_subdirectory(nlp)
add_library(
florisboard-native
SHARED
dev_patrickgold_florisboard_FlorisApplication.cpp
)
target_compile_options(florisboard-native PRIVATE -ffunction-sections -fdata-sections -fexceptions)
target_link_libraries(
# Destination
florisboard-native
# Sources
android
log
fl::nlp::core
utils
)

View File

@ -1,35 +0,0 @@
/*
* Copyright (C) 2021 Patrick Goldinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <fstream>
#include <vector>
#include <jni.h>
#include <unicode/udata.h>
#include "utils/jni_utils.h"
#include "fl_icuext.hpp"
#pragma ide diagnostic ignored "UnusedLocalVariable"
extern "C"
JNIEXPORT jint JNICALL
Java_dev_patrickgold_florisboard_FlorisApplication_00024Companion_nativeInitICUData(
JNIEnv *env, jobject thiz, jobject path)
{
auto path_str = utils::j2std_string(env, path);
auto status = fl::icuext::loadAndSetCommonData(path_str);
return status;
}

View File

@ -1,15 +0,0 @@
add_library(
# Name
utils
SHARED
# Headers
jni_utils.h
log.h
# Sources
jni_utils.cpp
log.cpp
)
target_link_libraries(utils PUBLIC log)

View File

@ -1,34 +0,0 @@
/*
* Copyright (C) 2021 Patrick Goldinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jni_utils.h"
#include "log.h"
std::string utils::j2std_string(JNIEnv *env, jobject jStr) {
auto cStr = reinterpret_cast<const char *>(env->GetDirectBufferAddress(jStr));
auto size = env->GetDirectBufferCapacity(jStr);
std::string stdStr(cStr, size);
utils::log(ANDROID_LOG_DEBUG, "spell j2s", stdStr);
return stdStr;
}
jobject utils::std2j_string(JNIEnv *env, const std::string& stdStr) {
utils::log(ANDROID_LOG_DEBUG, "spell s2j", stdStr);
size_t byteCount = stdStr.length();
auto cStr = stdStr.c_str();
auto buffer = env->NewDirectByteBuffer((void *) cStr, byteCount);
return buffer;
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2021 Patrick Goldinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FLORISBOARD_JNI_UTILS_H
#define FLORISBOARD_JNI_UTILS_H
#include <jni.h>
#include <string>
namespace utils {
std::string j2std_string(JNIEnv *env, jobject jStr);
jobject std2j_string(JNIEnv *env, const std::string& in);
} // namespace utils
#endif // FLORISBOARD_JNI_UTILS_H

View File

@ -1,75 +0,0 @@
/*
* Copyright (C) 2021 Patrick Goldinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <android/log.h>
#include <cerrno>
#include <cstring>
#include <fstream>
#include <iostream>
#include <thread>
#include <unistd.h>
#include "log.h"
void utils::log(int log_priority, const std::string &tag, const std::string &msg) {
__android_log_print(log_priority, tag.c_str(), "%s", msg.c_str());
}
/**
* Code below based on:
* https://codelab.wordpress.com/2014/11/03/how-to-use-standard-output-streams-for-logging-in-android-apps/
*/
int utils::start_stdout_stderr_logger(const std::string &app_name) {
static bool already_started = false;
if (already_started)
return 0;
int piperw[2];
if (pipe(piperw) < 0) {
std::string msg = "pipe(): ";
msg += strerror(errno);
utils::log(ANDROID_LOG_ERROR, "stdout/stderr logger", std::ref(msg));
return 1;
}
/* make stdout line-buffered and stderr unbuffered */
setvbuf(stdout, nullptr, _IOLBF, 0);
setvbuf(stderr, nullptr, _IONBF, 0);
/* create the pipe and redirect stdout and stderr */
dup2(piperw[0], STDIN_FILENO);
dup2(piperw[1], STDOUT_FILENO);
dup2(piperw[1], STDERR_FILENO);
close(piperw[0]);
close(piperw[1]);
auto f = [](const std::string &tag) {
std::string buf;
while (std::getline(std::cin, buf)) {
char &back = buf.back();
if (back == '\n')
back = '\0';
utils::log(ANDROID_LOG_DEBUG, tag, std::ref(buf));
}
};
/* spawn the logging thread */
std::thread thr(f, app_name);
thr.detach();
already_started = true;
return 0;
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (C) 2021 Patrick Goldinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FLORISBOARD_LOG_H
#define FLORISBOARD_LOG_H
#include <android/log.h>
#include <string>
namespace utils {
void log(int log_priority, const std::string &tag, const std::string &msg);
int start_stdout_stderr_logger(const std::string &app_name);
} // namespace utils
#endif // FLORISBOARD_LOG_H