Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support #978

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ python/startposesupload.txt
for_release/

tests/results/matchsgfs/
tests/results/matchsgfs2/
tests/results/matchsgfs2/

android/app/src/main/jniLibs/arm64-v8a/libOpenCL.so
android/app/src/main/jniLibs/armeabi-v7a/libOpenCL.so
15 changes: 15 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
31 changes: 31 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Android gradle project for building katago

## Building
Open the project in android studio, it was tested with Android Studio `2024.1.1 Patch 1`

### Obtaining libOpenCL.so
The headers used in this project in `app/src/main/cpp/include` come from https://github.com/krrishnarraj/libopencl-stub

libOpenCL.so is not commonly freely available, so it's easiest to copy it from a phone.
This works on most devices, like Xiaomi Redmi or Lenovo Tab, but it seems not to work with Google pixel 7a.

Copying the libOpenCL.so from your android device:
- enable developer options on your phone and enable usb or wifi debugging
- connect the phone to your development computer, it should show up in the device manager of android studio
- make sure you have adb, it can be install on ubuntu using `sudo apt install google-android-platform-tools-installer`
- open a terminal and do the following:
```
cd <path to KataGo repo>/android/app/src/main/jniLibs
adb pull /vendor/lib64/libOpenCL.so arm64-v8a/
adb pull /vendor/lib/libOpenCL.so armeabi-v7a/
```
if adb pull says there are multiple devices you can obtain the device id and add -s to the command like so:
```
adb devices -l
$ adb devices -l
List of devices attached
23011WERA0ADER device 4-1 product:lynx model:Pixel_7a device:lynx transport_id:192
adb-HA1KX6ED-J5mLEN._adb-tls-connect._tcp device product:TB-J616F_EEA model:Lenovo_TB_J616F device:TB-J616F transport_id:78
adb -s adb-HA1KX6ED-J5mLEN._adb-tls-connect._tcp pull /vendor/lib64/libOpenCL.so arm64-v8a/ arm64-v8a/
adb -s adb-HA1KX6ED-J5mLEN._adb-tls-connect._tcp pull /vendor/lib/libOpenCL.so armeabi-v7a/ armeabi-v7a/
```
1 change: 1 addition & 0 deletions android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
62 changes: 62 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
plugins {
alias(libs.plugins.android.application)
}

android {
namespace = "nl.jopdorp.katago"
compileSdk = 34

defaultConfig {
applicationId = "nl.jopdorp.katago"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

ndk {
abiFilters += listOf("armeabi-v7a", "arm64-v8a")
}

externalNativeBuild {
cmake {
arguments += listOf(
"-DUSE_BACKEND=opencl",
"-DBUILD_DISTRIBUTED=0",
"-DOpenCL_INCLUDE_DIR=${projectDir}/src/main/include"
)
}
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
}
}
}

dependencies {

implementation(libs.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}
21 changes: 21 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nl.jopdorp.katago;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("nl.jopdorp.katago", appContext.getPackageName());
}
}
16 changes: 16 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.KataGo"
tools:targetApi="31" />

</manifest>
1 change: 1 addition & 0 deletions android/app/src/main/cpp
Loading