Skip to content

Commit

Permalink
Use latest Bare Kit
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Dec 7, 2024
1 parent 167e16a commit 2406f47
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 176 deletions.
4 changes: 0 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ BinPackParameters: false
ContinuationIndentWidth: 2
ColumnLimit: 0
SpaceAfterCStyleCast: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterFunctionDeclarationName: true
AfterFunctionDefinitionName: true
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
49 changes: 23 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,29 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
host: linux
platform: android
- os: macos-latest
host: darwin
platform: android
- os: windows-latest
host: win32
platform: android
- os: ubuntu-latest
host: linux
platform: android
- os: macos-latest
host: darwin
platform: android
runs-on: ${{ matrix.os }}
name: ${{ matrix.host }}-${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/cache@v4
with:
path: vendor/bare-kit/vendor/bare/corestore
key: corestore-${{ matrix.host }}
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- run: npm install -g bare-dev
- run: bare-dev android sdk licenses accept
- run: bare-dev build --gradle
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: android/build/_drive
key: corestore-${{ matrix.host }}
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- run: npm install
- run: gh release download --repo holepunchto/bare-kit v1.0.0
- run: unzip prebuilds.zip "android/bare-kit/*" -d prebuilds/
- run: mv prebuilds/android/bare-kit app/libs/
- run: gradle build
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ node_modules/
package-lock.json
local.properties
*.bundle
*.bundle.h
*.d
*.zip
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"prettier-config-standard"
44 changes: 0 additions & 44 deletions CMakeLists.txt

This file was deleted.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Example of embedding Bare in an Android application using <https://github.com/holepunchto/bare-kit>.

## Building

To keep the build process fast and efficient, the project relies on a Bare Kit prebuild being available in the `app/libs/bare-kit` directory. Prior to building the project, you must therefore either clone and compile Bare Kit from source, or download the latest prebuild from GitHub. The latter is easily accomplished using the [GitHub CLI](https://cli.github.com):

```console
gh release download --repo holepunchto/bare-kit <version>
```

Unpack the resulting `prebuilds.zip` archive and move the `prebuilds/android/bare-kit` directory into `app/libs`. When finished, either open the project in Android Studio or build it from the commandline:

```console
gradle build
```

## License

Apache-2.0
64 changes: 36 additions & 28 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
plugins {
id 'com.android.application'
id "com.android.application"
}

android {
namespace 'to.holepunch.bare.android'
namespace "to.holepunch.bare.android"
compileSdk 34
ndkVersion '27.0.12077973'
ndkVersion "27.2.12479018"

defaultConfig {
applicationId 'to.holepunch.bare.android'
minSdk 31
applicationId "to.holepunch.bare.android"
minSdk 28
targetSdk 34
versionCode 1
versionName '1.0'
versionName "1.0"
}

externalNativeBuild {
cmake {
targets 'bare_android'
arguments "-DCMAKE_MODULE_PATH=$System.env.CMAKE_MODULE_PATH", "-DANDROID_STL=none"
}
sourceSets {
main {
jniLibs.srcDirs "src/main/addons", "libs/bare-kit/jni"
}
}
}

buildFeatures {
prefab true
}
task link(type: Exec) {
workingDir ".."

commandLine([
"npx", "bare-link",
"--target", "android-arm",
"--target", "android-arm64",
"--target", "android-ia32",
"--target", "android-x64",
"--needs", "libbare-kit.so",
"--out", "app/src/main/addons"
])
}

buildTypes {
release {
signingConfig signingConfigs.debug
}
}
task pack(type: Exec) {
workingDir ".."

externalNativeBuild {
cmake {
version '3.25.0+'
path '../CMakeLists.txt'
}
}
commandLine([
"npx", "bare-pack",
"--platform", "android",
"--linked",
"--out", "app/src/main/assets/app.bundle",
"app/src/main/js/app.js"
])
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
preBuild.dependsOn link, pack

implementation 'to.holepunch:bare-kit'
dependencies {
api fileTree(dir: "libs", include: ["bare-kit/classes.jar"])
}
File renamed without changes.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/addons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
46 changes: 6 additions & 40 deletions app/src/main/java/to/holepunch/bare/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,46 @@

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import to.holepunch.bare.kit.IPC;
import to.holepunch.bare.kit.RPC;
import to.holepunch.bare.kit.Worklet;

public class MainActivity extends Activity {
static {
System.loadLibrary("app");
}

Worklet worklet;
IPC ipc;
RPC rpc;

@Override
public void
onCreate (Bundle savedInstanceState) {
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

worklet = new Worklet();
worklet = new Worklet(null);

try {
worklet.start("/app.bundle", getAssets().open("app.bundle"));
worklet.start("/app.bundle", getAssets().open("app.bundle"), null);
} catch (Exception e) {
throw new RuntimeException(e);
}

ipc = new IPC(worklet);

rpc = new RPC(ipc, (req, error) -> {
if (req.command.equals("ping")) {
Log.i("bare", req.data("UTF-8"));

req.reply("Pong from Android", "UTF-8");
}
});

RPC.OutgoingRequest req = rpc.request("ping");

req.send("Ping from Android", "UTF-8");

req.reply("UTF-8", (data, error) -> {
Log.i("bare", data);
});
}

@Override
public void
onPause () {
onPause() {
super.onPause();

worklet.suspend();
}

@Override
public void
onResume () {
onResume() {
super.onResume();

worklet.resume();
}

@Override
public void
onDestroy () {
onDestroy() {
super.onDestroy();

try {
ipc.close();
ipc = null;
} catch (Exception e) {
throw new RuntimeException(e);
}

worklet.terminate();
worklet = null;
}
Expand Down
21 changes: 1 addition & 20 deletions app/src/main/js/app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
/* global Bare, BareKit */

Bare
.on('suspend', () => console.log('suspended'))
.on('resume', () => console.log('resumed'))
.on('exit', () => console.log('exited'))

const rpc = new BareKit.RPC((req) => {
if (req.command === 'ping') {
console.log(req.data.toString())

req.reply('Pong from Bare')
}
})

const req = rpc.request('ping')

req.send('Ping from Bare')

req.reply().then((data) => console.log(data.toString()))
console.log('Hello Android!')
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id 'com.android.application' version '8.4.0' apply false
id "com.android.application" version "8.4.0" apply false
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
},
"homepage": "https://github.com/holepunchto/bare-android#readme",
"devDependencies": {
"standard": "^17.0.0"
"bare-link": "^1.0.4",
"bare-pack": "^1.1.5",
"cmake-bare-bundle": "^2.1.3",
"prettier": "^3.4.2",
"prettier-config-standard": "^7.0.0"
}
}
6 changes: 1 addition & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ dependencyResolutionManagement {
}
}

rootProject.name = 'Bare'

include ':app'

includeBuild 'vendor/bare-kit'
include ":app"
1 change: 0 additions & 1 deletion vendor/bare-kit
Submodule bare-kit deleted from b63907

0 comments on commit 2406f47

Please sign in to comment.