Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
17 changes: 15 additions & 2 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
name: Android Build

on:
pull_request:
schedule:
# Run nightly at midnight UTC
- cron: '0 0 * * *'
Expand Down Expand Up @@ -35,38 +36,49 @@ jobs:
path: mv3/android/MV3Demo
- name: YoloDemo
path: Yolo/android
- name: WhisperDemo
path: whisper/android/WhisperApp
require_aar: true
- name: ParakeetDemo
path: parakeet/android/ParakeetApp
require_aar: true


name: Build ${{ matrix.name }}
steps:
- name: Checkout repository
if: ${{ !matrix.require_aar || inputs.local_aar }}
uses: actions/checkout@v4

Comment on lines 49 to 52

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matrix marks Whisper/Parakeet as require_aar: true and then conditionally skips checkout/JDK/Gradle/build steps when inputs.local_aar is not provided. This yields matrix jobs that do no work but still succeed, which can hide build regressions. Prefer a job-level if: (or matrix exclude) to skip those entries entirely, or remove require_aar if the Maven dependency fallback is sufficient.

Copilot uses AI. Check for mistakes.
- name: Set up JDK 17
if: ${{ !matrix.require_aar || inputs.local_aar }}
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
if: ${{ !matrix.require_aar || inputs.local_aar }}
uses: gradle/actions/setup-gradle@v4

- name: Download local AAR
if: ${{ inputs.local_aar && (matrix.name == 'LlamaDemo' || matrix.name == 'YoloDemo') }}
if: ${{ inputs.local_aar && (matrix.name == 'LlamaDemo' || matrix.name == 'YoloDemo' || matrix.name == 'WhisperDemo' || matrix.name == 'ParakeetDemo') }}
run: |
mkdir -p ${{ matrix.path }}/app/libs
curl -fL -o ${{ matrix.path }}/app/libs/executorch.aar "${{ inputs.local_aar }}"

- name: Build with Gradle
if: ${{ !matrix.require_aar || inputs.local_aar }}
working-directory: ${{ matrix.path }}
run: |
if [ -n "${{ inputs.local_aar }}" ] && ([ "${{ matrix.name }}" == "LlamaDemo" ] || [ "${{ matrix.name }}" == "YoloDemo" ]); then
if [ -n "${{ inputs.local_aar }}" ] && ([ "${{ matrix.name }}" == "LlamaDemo" ] || [ "${{ matrix.name }}" == "YoloDemo" ] || [ "${{ matrix.name }}" == "WhisperDemo" ] || [ "${{ matrix.name }}" == "ParakeetDemo" ]); then
./gradlew build --no-daemon -PuseLocalAar=true
else
./gradlew build --no-daemon
fi

- name: Rename APKs with demo name
if: ${{ !matrix.require_aar || inputs.local_aar }}
working-directory: ${{ matrix.path }}/app/build/outputs/apk/
run: |
find . -name "*.apk" -type f -print0 | while IFS= read -r -d '' apk; do
Expand All @@ -78,6 +90,7 @@ jobs:
done

- name: Upload build artifacts
if: ${{ !matrix.require_aar || inputs.local_aar }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-apk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}
Comment on lines 80 to 98

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Activity no longer closes birdPipeline (and likely the underlying native Modules) on lifecycle events. Without an onDestroy (and/or onStop) cleanup, the native models + cameraExecutor thread can leak when the Activity is finished or recreated. Reintroduce lifecycle cleanup and shut down cameraExecutor as well.

Copilot uses AI. Check for mistakes.

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

// Clean up the detection pipeline
if (detectionPipeline != null) {
detectionPipeline.close();
detectionPipeline = null;
}

Log.d(TAG, "BirdDetectionActivity destroyed");
}

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

// Optional: Release resources when app goes to background
if (detectionPipeline != null) {
detectionPipeline.close();
detectionPipeline = null;
}
}

private void initializeViews() {
previewView = findViewById(R.id.previewView);
overlayImageView = findViewById(R.id.overlayImageView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,19 @@ private void loadBirdSpeciesNames(Context context) throws IOException {
public List<BirdDetection> detectBirds(Bitmap bitmap) {
List<BirdDetection> results = new ArrayList<>();
frameCounter++;

Tensor yoloInput = null;
EValue[] yoloOutputs = null;


try {
// Cleanup old detection history every 30 frames
if (frameCounter % 30 == 0) {
cleanupOldDetections();
}
yoloInput = preprocessForYolo(bitmap);

Tensor yoloInput = preprocessForYolo(bitmap);
if (yoloInput == null) {
return results;
}
yoloOutputs = yoloModule.forward(EValue.from(yoloInput));

EValue[] yoloOutputs = yoloModule.forward(EValue.from(yoloInput));
if (yoloOutputs == null || yoloOutputs.length == 0) {
return results;

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detectBirds no longer closes Tensor yoloInput and EValue[] yoloOutputs. In ExecuTorch/PyTorch Android these objects typically hold native memory; skipping close()/release will leak memory across frames. Restore deterministic cleanup (e.g., try/finally or try-with-resources) for both the input tensor and each output EValue, even on early returns/exceptions.

Copilot uses AI. Check for mistakes.
}
Expand Down Expand Up @@ -240,29 +237,8 @@ public List<BirdDetection> detectBirds(Bitmap bitmap) {

} catch (Exception e) {
Log.e(TAG, "Error in detectBirds", e);
} finally {
// CRITICAL: Release tensors to prevent memory leak
if (yoloInput != null) {
try {
yoloInput.close();
} catch (Exception e) {
Log.e(TAG, "Error closing yoloInput", e);
}
}

if (yoloOutputs != null) {
for (EValue output : yoloOutputs) {
if (output != null) {
try {
output.close();
} catch (Exception e) {
Log.e(TAG, "Error closing output", e);
}
}
}
}
}

return results;
}

Expand Down Expand Up @@ -596,19 +572,15 @@ private Tensor preprocessForClassifier(Bitmap bitmap) {
}
}

private String[] classifyBird(Bitmap bitmap, RectF boundingBox) throws Exception {
Bitmap croppedBird = cropBitmap(bitmap, boundingBox);
if (croppedBird == null) {
return new String[]{"Bird", "0.5"};
}

Tensor classifierInput = preprocessForClassifier(croppedBird);
private String classifyBird(Bitmap croppedBitmap) throws Exception {
Tensor classifierInput = preprocessForClassifier(croppedBitmap);
if (classifierInput == null) {
return new String[]{"Bird", "0.5"};
return "Bird";
}

EValue[] classifierOutputs = classifierModule.forward(EValue.from(classifierInput));
return parseClassifierOutput(classifierOutputs);
String[] result = parseClassifierOutput(classifierOutputs);
return result[0];

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classifyBird creates a Tensor and runs classifierModule.forward(...) but never closes the Tensor or the returned EValue[]. This will leak native resources over time. Add cleanup (try/finally or try-with-resources) for classifierInput and each classifierOutputs element after parsing.

Copilot uses AI. Check for mistakes.
}

private String[] parseClassifierOutput(EValue[] outputs) {
Expand Down
1 change: 1 addition & 0 deletions parakeet/android/ParakeetApp/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
debugImplementation(libs.androidx.ui.tooling)
if (useLocalAar == true) {
implementation(files("libs/executorch.aar"))
Expand Down
9 changes: 8 additions & 1 deletion whisper/android/WhisperApp/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
alias(libs.plugins.kotlin.compose)
}

val useLocalAar: Boolean? = (project.findProperty("useLocalAar") as? String)?.toBoolean()

android {
namespace = "com.example.whisperapp"
compileSdk = 35
Expand Down Expand Up @@ -46,7 +48,12 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
debugImplementation(libs.androidx.ui.tooling)
implementation(files("libs/executorch.aar"))
if (useLocalAar == true) {
implementation(files("libs/executorch.aar"))
} else {
implementation("org.pytorch:executorch-android:1.1.0")
}
implementation("com.facebook.fbjni:fbjni:0.5.1")
}
12 changes: 4 additions & 8 deletions whisper/android/WhisperApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<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.WhisperApp"
android:extractNativeLibs="true"
tools:targetApi="31">
android:theme="@android:style/Theme.Material.Light.NoActionBar"
android:extractNativeLibs="true">

<uses-native-library
android:name="libcdsprpc.so"
Expand All @@ -22,7 +18,7 @@
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.WhisperApp">
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
5 changes: 0 additions & 5 deletions whisper/android/WhisperApp/app/src/main/res/values/themes.xml

This file was deleted.

13 changes: 0 additions & 13 deletions whisper/android/WhisperApp/app/src/main/res/xml/backup_rules.xml

This file was deleted.

This file was deleted.