Skip to content

Commit

Permalink
Switch to GameActivity and gradle build
Browse files Browse the repository at this point in the history
Fixes: #189
Fixes: #190
Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Jan 28, 2025
1 parent 478603e commit 5d4548d
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
build.log
perf.data
perf.data.old
crates/notedeck_chrome/android/app/build
.privenv
*.so
*.swp
*.jar
target
.gradle
queries/damus-notifs.json
.git
cache
Expand All @@ -17,4 +21,4 @@ scripts/macos_build_secrets.sh
*.txt
/tags
*.mdb
.idea/
.idea/
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
.DEFAULT_GOAL := check
.PHONY: fake

all:
cargo check
ANDROID_DIR := crates/notedeck_chrome/android

check:
cargo check

tags: fake
find . -type d -name target -prune -o -type f -name '*.rs' -print | xargs ctags

.PHONY: fake
jni: fake
cargo ndk --target arm64-v8a -o $(ANDROID_DIR)/app/src/main/jniLibs/ build --profile release

apk: jni
cd $(ANDROID_DIR) && ./gradlew build

android: jni
cd $(ANDROID_DIR) && ./gradlew installDebug
adb shell am start -n com.damus.notedeck/.MainActivity
adb logcat -v color -s notedeck RustStdoutStderr
13 changes: 13 additions & 0 deletions crates/notedeck_chrome/android/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DEFAULT_GOAL := apk
.PHONY: jni apk run-on-device

jni:
cd rust && cargo ndk --target arm64-v8a -o ../java/app/src/main/jniLibs/ build --profile release

apk: jni
cd java && ./gradlew build

run-on-device: jni
cd java && ./gradlew installDebug
adb shell am start -n local.walkers/.MainActivity
adb logcat -v color -s walkers RustStdoutStderr
28 changes: 28 additions & 0 deletions crates/notedeck_chrome/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id "com.android.application"
}

android {
namespace "com.damus.notedeck"
compileSdk 31

defaultConfig {
minSdk 29
targetSdk 33
versionCode 1
versionName "1"
}

buildTypes {
debug
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation "com.google.android.material:material:1.5.0"
implementation "androidx.games:games-activity:2.0.2"
}
37 changes: 37 additions & 0 deletions crates/notedeck_chrome/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:label="Notedeck"
android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="main" />
</activity>
</application>

[[package.metadata.android.uses_feature]]
name = "android.hardware.vulkan.level"
required = true
version = 1

<uses-feature android:name="android.hardware.vulkan.level"
android:required="true"
android:version="1" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.damus.notedeck;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import androidx.core.graphics.Insets;
import androidx.core.view.DisplayCutoutCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.androidgamesdk.GameActivity;

public class MainActivity extends GameActivity {
static {
System.loadLibrary("main");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// Shrink view so it does not get covered by insets.

View content = getWindow().getDecorView().findViewById(android.R.id.content);
ViewCompat.setOnApplyWindowInsetsListener(content, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

return WindowInsetsCompat.CONSUMED;
});

WindowCompat.setDecorFitsSystemWindows(getWindow(), true);

super.onCreate(savedInstanceState);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
// Offset the location so it fits the view with margins caused by insets.

int[] location = new int[2];
findViewById(android.R.id.content).getLocationOnScreen(location);
event.offsetLocation(-location[0], -location[1]);
return super.onTouchEvent(event);
}
}
9 changes: 9 additions & 0 deletions crates/notedeck_chrome/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.4.1' apply false
id 'com.android.library' version '8.4.1' apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
}
22 changes: 22 additions & 0 deletions crates/notedeck_chrome/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonFinalResIds=false
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 5d4548d

Please sign in to comment.