Skip to content

Commit

Permalink
chore: full rewrite of the app using C++
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Oct 8, 2023
1 parent cfbaa14 commit 70bde77
Show file tree
Hide file tree
Showing 160 changed files with 4,763 additions and 6,705 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ e2e/**/*.js
/fastlane/report.xml
/gpx
/dist
build
/Gemfile.lock
firmware
firmwares
Expand Down
Empty file modified .vscode/i18n-ally-custom-framework.yml
100644 → 100755
Empty file.
Empty file modified .vscode/launch.json
100644 → 100755
Empty file.
79 changes: 60 additions & 19 deletions App_Resources/Android/app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ android {
def splitEnabled = (gradle.startParameter.taskNames.contains("assembleDebug") && project.hasProperty('abiFilters')) || project.hasProperty('splitEnabled');
defaultConfig {
multiDexEnabled false
applicationId "com.akylas.documentscanner"
minSdkVersion 21
versionCode 1
versionName "1.0.0"
Expand All @@ -25,19 +26,43 @@ android {
abiFilters.addAll(project.findProperty('abiFilters').split(',').collect{it as String})
}
}

}
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
abiFilters 'armeabi-v7a', "arm64-v8a", 'x86', 'x86_64'
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static"
}
}
}
ndkVersion = "25.2.9519653"
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
// kotlinOptions {
// jvmTarget = JavaVersion.VERSION_11
// }
lintOptions {
// disable("LintError")
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
bundle {
language {
// We disable language split because we do not use
// runtime Google Play Service APIs and thus cannot dynamically
// request to download the language resources for a specific locale.
enableSplit = false
}
}
splits {
abi {
enable splitEnabled
Expand All @@ -49,18 +74,19 @@ android {
universalApk project.hasProperty('universalApk')
}
}

// aaptOptions {
// additionalParameters "--no-version-vectors"
// }
buildTypes { // THIS CAUSES RELEASE MODE ERROR ON APP LAUNCH
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled false
// minifyEnabled true

// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources false
// shrinkResources true

// Disables PNG crunching for the release build type.
crunchPngs false
Expand All @@ -69,10 +95,10 @@ android {
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
def absolutePathToAppResources = getAppResourcesPath()
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
"$BUILD_TOOLS_PATH/proguard-rules.pro"
// def absolutePathToAppResources = getAppResourcesPath()
// proguardFiles getDefaultProguardFile(
// 'proguard-android-optimize.txt'),
// "$BUILD_TOOLS_PATH/proguard-rules.pro"

debuggable false
jniDebuggable false
Expand All @@ -82,6 +108,12 @@ android {
multiDexEnabled true;
}
}
packagingOptions {
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
}
// flavorDimensions "stage"
// productFlavors {
// dev {
Expand All @@ -105,14 +137,14 @@ android {
// }
// }
// }
tasks.whenTaskAdded({ DefaultTask currentTask ->
// if (currentTask =~ /buildMetadata/) {
// currentTask.finalizedBy(createProguard)
// }
// if (currentTask =~ /minify.*WithR8/) {
// currentTask.dependsOn(createProguard)
// }
})
// tasks.whenTaskAdded({ DefaultTask currentTask ->
// if (currentTask =~ /buildMetadata/) {
// currentTask.finalizedBy(createProguard)
// }
// if (currentTask =~ /minify.*WithR8/) {
// currentTask.dependsOn(createProguard)
// }
// })

android.applicationVariants.all { variant ->
if (project.hasProperty('splitEnabled')) {
Expand All @@ -128,7 +160,16 @@ android.applicationVariants.all { variant ->
}
}
dependencies {
implementation 'com.otaliastudios:cameraview:2.7.2'
// implementation 'cz.adaptech.android:tesseract4android:4.1.1'
implementation 'androidx.core:core-splashscreen:1.0.0-rc01'
}
def androidxVersion = project.hasProperty("androidxVersion") ? project.androidxVersion : "1.2.0"
implementation "androidx.core:core-ktx:$androidxVersion"
implementation 'com.otaliastudios:cameraview:2.7.2'
implementation 'androidx.core:core-splashscreen:1.0.0'
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}
}
27 changes: 16 additions & 11 deletions App_Resources/Android/before-plugins.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
ext {
compileSdk = 32
targetSdk = 32
buildToolsVersion = "33.0.0"
androidxVersion = "1.8.0"
androidXAppCompat = "1.3.1"
androidXAppCompatVersion = "1.3.1"
androidXFragment = "1.4.1"
compileSdk = 34
targetSdk = 34
androidBuildToolsVersion = "7.3.0"
buildToolsVersion = "33.0.1"
androidxVersion = "1.12.0"
androidXAppCompat = "1.6.1"
androidXAppCompatVersion = "1.6.1"
androidXFragment = "1.6.1"
androidXTransition = "1.4.1"
androidXRecyclerViewVersion = "1.2.1"
androidXSwipeRefreshLayoutViewVersion = "1.1.0"
androidXMaterial = "1.6.1"
androidXBrowser = "1.4.0"
androidXRecyclerViewVersion = "1.3.1"
androidxViewPager2Version = "1.1.0-beta02"
androidXSwipeRefreshLayoutViewVersion = "1.2.0-alpha01"
androidXMaterial = "1.9.0"
androidXBrowser = "1.6.0"
androidXPreferenceVersion = "1.2.1"
okHttpVersion = "4.10.0"
frescoVersion = "3.1.0"
}
26 changes: 0 additions & 26 deletions App_Resources/Android/dependency-report.gradle

This file was deleted.

4 changes: 2 additions & 2 deletions App_Resources/Android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION=7.2.1
# ns_default_kotlin_version=1.7.10
android.enableJetifier=false
android.enableR8.fullMode=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true
org.gradle.jvmargs=-XX:+UseParallelGC
useKotlin=true
1 change: 1 addition & 0 deletions App_Resources/Android/opencv
6 changes: 3 additions & 3 deletions App_Resources/Android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="__PACKAGE__">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="__PACKAGE__">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand All @@ -17,8 +17,8 @@
<activity android:name="com.nativescript.preferences.NativescriptSettingsActivity" android:theme="@style/SettingsTheme" android:exported="true" />
<meta-data android:name="io.sentry.anr.enable" android:value="false" />
<meta-data android:name="android.webkit.WebView.MetricsOptOut" android:value="true" />
<provider android:name="androidx.core.content.FileProvider" android:authorities="__PACKAGE__.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
<provider android:name="androidx.core.content.FileProvider" android:authorities="__PACKAGE__.provider" android:exported="false" android:grantUriPermissions="true" tools:replace="android:authorities">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" tools:replace="android:resource" />
</provider>
</application>
</manifest>
51 changes: 51 additions & 0 deletions App_Resources/Android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

set(TARGET document_detector)
set(SRC_DIR ./)
set(SRC_DIR2 ./src)
set(OPENCV_LIB_DIR opencv/staticlibs/${ANDROID_ABI}/)
set(OPENCV_3RD_LIB_DIR opencv/3rdparty/libs/${ANDROID_ABI}/)

include_directories(opencv/include
./include)


link_directories(${OPENCV_LIB_DIR}
${OPENCV_3RD_LIB_DIR})


# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

aux_source_directory(${SRC_DIR} DIR_LIB_SOURCE)
aux_source_directory(${SRC_DIR2} DIR_LIB_SOURCE2)

add_library(${TARGET} SHARED ${DIR_LIB_SOURCE} ${DIR_LIB_SOURCE2})

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

target_link_libraries(${TARGET} log jnigraphics z dl m)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

if(${ANDROID_ABI} STREQUAL x86_64)
target_link_libraries(${TARGET} opencv_imgproc opencv_core cpufeatures libprotobuf ade tbb ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf quirc)
elseif(${ANDROID_ABI} STREQUAL x86)
target_link_libraries(${TARGET} opencv_imgproc opencv_core cpufeatures libprotobuf ade tbb ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf quirc ippiw ippicv)
else()
target_link_libraries(${TARGET} opencv_imgproc opencv_core cpufeatures libprotobuf ade tbb ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf quirc tegra_hal)
endif()

76 changes: 76 additions & 0 deletions App_Resources/Android/src/main/cpp/android_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "android_utils.h"

void bitmap_to_mat(JNIEnv *env, jobject &srcBitmap, Mat &srcMat) {
void *srcPixels = 0;
AndroidBitmapInfo srcBitmapInfo;
try {
AndroidBitmap_getInfo(env, srcBitmap, &srcBitmapInfo);
AndroidBitmap_lockPixels(env, srcBitmap, &srcPixels);
uint32_t srcHeight = srcBitmapInfo.height;
uint32_t srcWidth = srcBitmapInfo.width;
srcMat.create(srcHeight, srcWidth, CV_8UC4);
if (srcBitmapInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) {
Mat tmp(srcHeight, srcWidth, CV_8UC4, srcPixels);
tmp.copyTo(srcMat);
} else {
Mat tmp = Mat(srcHeight, srcWidth, CV_8UC2, srcPixels);
cvtColor(tmp, srcMat, COLOR_BGR5652RGBA);
}
AndroidBitmap_unlockPixels(env, srcBitmap);
return;
} catch (cv::Exception &e) {
AndroidBitmap_unlockPixels(env, srcBitmap);
jclass je = env->FindClass("java/lang/Exception");
env -> ThrowNew(je, e.what());
return;
} catch (...) {
AndroidBitmap_unlockPixels(env, srcBitmap);
jclass je = env->FindClass("java/lang/Exception");
env -> ThrowNew(je, "unknown");
return;
}
}

void mat_to_bitmap(JNIEnv *env, Mat &srcMat, jobject &dstBitmap) {
void *dstPixels = 0;
AndroidBitmapInfo dstBitmapInfo;
try {
AndroidBitmap_getInfo(env, dstBitmap, &dstBitmapInfo);
AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels);
uint32_t dstHeight = dstBitmapInfo.height;
uint32_t dstWidth = dstBitmapInfo.width;
if (dstBitmapInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) {
Mat tmp(dstHeight, dstWidth, CV_8UC4, dstPixels);
if(srcMat.type() == CV_8UC1) {
cvtColor(srcMat, tmp, COLOR_GRAY2RGBA);
} else if (srcMat.type() == CV_8UC3) {
cvtColor(srcMat, tmp, COLOR_RGB2RGBA);
} else if (srcMat.type() == CV_8UC4) {
srcMat.copyTo(tmp);
}
} else {
Mat tmp = Mat(dstHeight, dstWidth, CV_8UC2, dstPixels);
if(srcMat.type() == CV_8UC1) {
cvtColor(srcMat, tmp, COLOR_GRAY2BGR565);
} else if (srcMat.type() == CV_8UC3) {
cvtColor(srcMat, tmp, COLOR_RGB2BGR565);
} else if (srcMat.type() == CV_8UC4) {
cvtColor(srcMat, tmp, COLOR_RGBA2BGR565);
}
}
AndroidBitmap_unlockPixels(env, dstBitmap);
}catch (cv::Exception &e) {
AndroidBitmap_unlockPixels(env, dstBitmap);
jclass je = env->FindClass("java/lang/Exception");
env -> ThrowNew(je, e.what());
return;
} catch (...) {
AndroidBitmap_unlockPixels(env, dstBitmap);
jclass je = env->FindClass("java/lang/Exception");
env -> ThrowNew(je, "unknown");
return;
}
}



Loading

0 comments on commit 70bde77

Please sign in to comment.