Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ChessAndroid/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10)
set(LIB_NAME "chess")
project(${LIB_NAME})

set(CMAKE_CXX_EXTENSIONS OFF)

add_library(
${LIB_NAME}
SHARED
Expand Down Expand Up @@ -33,9 +35,7 @@ target_compile_options(${LIB_NAME} PUBLIC
-Wpedantic -Wnull-dereference
)

set(FLAGS_DEBUG "-O1")
set(FLAGS_RELEASE "-DNDEBUG" "-flto=thin" "-O3")
target_compile_options(${LIB_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${FLAGS_DEBUG}>")
target_compile_options(${LIB_NAME} PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:${FLAGS_RELEASE}>")
target_compile_options(${LIB_NAME} PUBLIC "$<$<CONFIG:RELEASE>:${FLAGS_RELEASE}>")

Expand Down
22 changes: 6 additions & 16 deletions ChessAndroid/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ android {
applicationId "net.theluckycoder.chess"
minSdkVersion 21
targetSdkVersion 30
versionCode 1200
versionCode 1204
versionName "1.2.0"
resConfigs "en"
}

buildTypes {
Expand All @@ -19,12 +20,6 @@ android {
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

externalNativeBuild {
cmake {
abiFilters "arm64-v8a", "armeabi-v7a"
}
}

packagingOptions {
resources {
excludes.add("DebugProbesKt.bin")
Expand All @@ -33,11 +28,6 @@ android {
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildFeatures.compose = true

composeOptions {
Expand Down Expand Up @@ -68,18 +58,18 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
dependencies {
// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
debugImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3")

// AndroidX
implementation("androidx.activity:activity-ktx:1.2.2")
implementation("androidx.activity:activity-ktx:1.2.3")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1")
implementation("androidx.datastore:datastore-preferences:1.0.0-alpha08")
implementation("androidx.datastore:datastore-preferences:1.0.0-beta01")

// Compose
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation("androidx.compose.foundation:foundation:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
debugImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04")
}
1 change: 1 addition & 0 deletions ChessAndroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:isGame="true"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">

Expand Down
33 changes: 0 additions & 33 deletions ChessAndroid/app/src/main/cpp/JniCache.h

This file was deleted.

77 changes: 77 additions & 0 deletions ChessAndroid/app/src/main/cpp/JniUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pragma once

#include <android/log.h>
#include <cassert>

#define LOGV(LOG_TAG, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGI(LOG_TAG, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGD(LOG_TAG, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGW(LOG_TAG, ...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(LOG_TAG, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

/**
* This class automatically attaches this thread to the JVM if necessary,
* and detaches it upon destruction.
* And it provides a valid pointer to the JNIEnv.
*
* In this way it works similarly to the std::lock_guard class.
*/
class NativeThreadAttach
{
public:
explicit NativeThreadAttach(JavaVM *jvm)
: _jvm(jvm)
{
_jvmEnvState = _jvm->GetEnv(reinterpret_cast<void **>(&_env), JNI_VERSION_1_6);

if (_jvmEnvState == JNI_EDETACHED)
_jvm->AttachCurrentThread(&_env, nullptr);
_env->ExceptionClear();
}

JNIEnv *getEnv() { return _env; }

~NativeThreadAttach()
{
if (_jvmEnvState == JNI_EDETACHED)
_jvm->DetachCurrentThread();
}

private:
JavaVM *_jvm;
JNIEnv *_env = nullptr;
int _jvmEnvState{};
};

namespace JniCache
{
jclass boardChangeListenerClass;
jclass searchListenerClass;
jclass indexedPieceClass;
jclass moveClass;
jclass searchOptionsClass;

static jclass cacheClass(JNIEnv *env, const char *name)
{
return static_cast<jclass>(env->NewGlobalRef(env->FindClass(name)));
}

void createCaches(JNIEnv *env)
{
boardChangeListenerClass = cacheClass(env, "net/theluckycoder/chess/cpp/BoardChangeListener");
searchListenerClass = cacheClass(env, "net/theluckycoder/chess/cpp/SearchListener");
indexedPieceClass = cacheClass(env, "net/theluckycoder/chess/model/IndexedPiece");
moveClass = cacheClass(env, "net/theluckycoder/chess/model/Move");
searchOptionsClass = cacheClass(env, "net/theluckycoder/chess/model/SearchOptions");
}

void cleanCaches(JNIEnv *env)
{
env->DeleteGlobalRef(boardChangeListenerClass);
env->DeleteGlobalRef(searchListenerClass);
env->DeleteGlobalRef(indexedPieceClass);
env->DeleteGlobalRef(moveClass);
env->DeleteGlobalRef(searchOptionsClass);
}
}

9 changes: 0 additions & 9 deletions ChessAndroid/app/src/main/cpp/Log.h

This file was deleted.

Loading