Your GitHub repository has been successfully created:
- Repository: AAYUSHBHURE/android-native-cpp-project
- URL: https://github.com/AAYUSHBHURE/android-native-cpp-project
- Local Path: C:\Users\bhure\FLAM\android-native-cpp-project
## Quick Commands for After Android Studio Project Creation:
---```powershell
git commit -m "Initial project setup with NDK support"
Note: Record a GIF showing the toggle button switching between raw camera and edge detection modes, then add it here:git push origin master
The repository is ready and waiting for your Android Native C++ project files!
Toggle between raw camera feed and edge-detected output in real-time
- Camera Feed Implementation - Live camera preview using Camera2 API
- Camera2 API Integration - Modern Android camera access with TextureView
- Runtime Permission Handling - Proper permission request flow
- OpenCV Native Integration - C++ JNI bridge for image processing
- CMake Build System - Native library compilation with NDK
- OpenCV Version Display - Shows OpenCV 4.8.0 information
- Toggle Button - Switch between raw camera and edge-detected output
- FPS Counter - Real-time performance monitoring (top-right overlay)
- Frame Saving - Capture and save frames to device storage
- TypeScript Web Viewer - Separate web app to view saved frames
- JNI Frame Processing - Native method for OpenCV edge detection (stub ready for Canny filter)
- Modern UI Design - Material Design with semi-transparent overlays
- Comprehensive Documentation - Setup guides, testing instructions, and commit templates
- Background Thread Handling - Proper camera operations on background thread
- MediaStore Integration - Android 10+ compliant file storage
- Dual Save Locations - Timestamped + fixed filename for web viewer
- Error Handling - Robust exception handling throughout
- Logging - Detailed logcat output for debugging
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Android App Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Camera2 API β TextureView β onSurfaceTextureUpdated() β
β β β β β
β β β β β
β β β ββββββββββββββββββββ β
β β β β FPS Tracking β β
β β β β UI Updates β β
β β β ββββββββββββββββββββ β
β β β β
β β βββββββ TextureView.bitmap β
β β β β
β β β β
β β βββββββββββββββββββ β
β β β Save Frame β β
β β β (MediaStore) β β
β β βββββββββββββββββββ β
β β β
β βββββββ [Future] JNI Bridge β
β β β
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Native C++ Layer (JNI) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β processFrame(enableEdgeDetection: Boolean) β
β β β
β βββ if (edgeDetection) β
β β cv::Canny(input, output, 50, 150) β
β β β
β βββ else β
β return raw frame β
β β
β OpenCV 4.8.0 (libopencv_java4.so + static libs) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TypeScript Web Viewer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Saved Frame (frame.jpg) β
β β β
β β β
β Display with Stats Overlay β
β β’ FPS β
β β’ Resolution β
β β’ Processing Mode β
β β’ OpenCV Version β
β β’ Timestamp β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- MainActivity.kt: Main activity managing camera lifecycle, UI, and frame processing
- ActivityMainBinding: ViewBinding for type-safe view access
- Camera2 API: Modern camera access with manual control
- TextureView: Surface for camera preview rendering
- FPS Counter: Real-time frame rate calculation and display
- Toggle Control: Switch between raw and edge-detected modes
- Frame Saving: MediaStore API for Android 10+ compatibility
- native-lib.cpp: JNI bridge to OpenCV
stringFromJNI()
: Test methodgetOpenCVVersion()
: Returns OpenCV version stringtestOpenCVMat()
: Validates OpenCV matrix operationsprocessFrame()
: Frame processing with edge detection toggle (ready for Canny implementation)
- CMakeLists.txt: Build configuration linking OpenCV
- OpenCV 4.8.0 Android SDK
- Pre-built native libraries for all ABIs (arm64-v8a, armeabi-v7a, x86, x86_64)
- Java wrapper classes (org.opencv.*)
- CMake configuration files
- TypeScript modern web application
- Glassmorphism UI design
- Frame display with automatic refresh
- Stats overlay showing processing metadata
- Development server with hot reload
- Android Studio: Arctic Fox (2020.3.1) or newer
- Android NDK: 27.0.12077973
- CMake: 3.22.1 or newer
- Android SDK:
- Build Tools: 36.1.0
- Target SDK: 36 (Android 15)
- Minimum SDK: 24 (Android 7.0)
- OpenCV: 4.8.0 (included in project)
- Node.js: 16.x or newer (for web viewer)
- npm: 8.x or newer
git clone https://github.com/AAYUSHBHURE/android-native-cpp-project.git
cd android-native-cpp-project
# Open Android Studio
# File β Open β Select android-native-cpp-project folder
- Go to File β Settings β Build, Execution, Deployment β Build Tools β Gradle
- Set Gradle JDK to Embedded JDK (JBR 21) or Android Studio's JBR
- Click Sync Now when prompted, or
- File β Sync Project with Gradle Files
# From terminal in project root
./gradlew clean :app:assembleDebug
# On Windows
gradlew.bat clean :app:assembleDebug
Option A: Physical Device (Recommended)
- Enable Developer Options on your Android device
- Enable USB Debugging
- Connect via USB
- Run from Android Studio or:
./gradlew installDebug adb shell am start -n com.example.project_flam/.MainActivity
Option B: Emulator
- Create AVD: Tools β Device Manager β Create Device
- Select Pixel 9a or similar
- System Image: API 35 or 36 (Google APIs)
- Enable Hardware: Camera in Advanced Settings
- Start emulator and run app
cd web
# Install dependencies
npm install
# Build TypeScript
npm run build
# Start development server
npm run serve
Open browser to http://localhost:8080
- Launch App: Grant camera permission when prompted
- View Camera Feed: Live preview appears in TextureView
- Check FPS: Top-right overlay shows current frame rate (~30 FPS)
- Toggle Processing:
- Switch OFF = Raw camera feed
- Switch ON = Edge detection mode (Canny filter ready to integrate)
- Save Frame: Tap "Save Frame" button
- Saves to
Pictures/frame_<timestamp>.jpg
- Also saves
frame.jpg
for web viewer
- Saves to
- Save a frame from Android app
- Copy frame to web directory:
adb pull /sdcard/Android/data/com.example.project_flam/files/Pictures/frame.jpg web/
- Open browser to
http://localhost:8080
- View frame with stats overlay (FPS, resolution, mode, OpenCV version)
android-native-cpp-project/
βββ app/ # Android app module
β βββ src/
β β βββ main/
β β β βββ java/com/example/project_flam/
β β β β βββ MainActivity.kt # Main activity (Camera2 + UI)
β β β βββ cpp/ # Native C++ code (JNI)
β β β β βββ native-lib.cpp # OpenCV integration
β β β β βββ CMakeLists.txt # CMake build config
β β β βββ res/
β β β β βββ layout/
β β β β βββ activity_main.xml # UI layout
β β β βββ AndroidManifest.xml # App manifest
β β βββ build.gradle.kts # App build config
β βββ build/ # Build outputs (gitignored)
β
βββ opencv/ # OpenCV 4.8.0 Android SDK
β βββ java/ # Java wrapper classes
β βββ native/ # Native libraries and headers
β β βββ jni/ # CMake configs, headers
β β βββ libs/ # Shared libraries (.so)
β β βββ staticlibs/ # Static libraries (.a)
β βββ build.gradle # OpenCV module config
β
βββ web/ # TypeScript web viewer
β βββ src/
β β βββ main.ts # Web viewer TypeScript
β βββ index.html # Web viewer HTML
β βββ package.json # npm dependencies
β βββ tsconfig.json # TypeScript config
β βββ README.md # Web viewer docs
β
βββ gradle/ # Gradle wrapper
βββ build.gradle.kts # Root build config
βββ settings.gradle.kts # Project settings
βββ IMPLEMENTATION_GUIDE.md # Implementation details
βββ TESTING_GUIDE.md # Testing instructions
βββ COMMIT_MESSAGES.md # Git commit templates
βββ README.md # This file
Component | Version |
---|---|
Android Gradle Plugin | 8.13.0 |
Gradle | 8.13 |
Kotlin | 2.0.21 |
NDK | 27.0.12077973 |
CMake | 3.22.1 |
Build Tools | 36.1.0 |
Target SDK | 36 (Android 15) |
Min SDK | 24 (Android 7.0) |
OpenCV | 4.8.0 |
TypeScript | 5.3.3 |
app/build.gradle.kts:
android {
namespace = "com.example.project_flam"
compileSdk = 36
ndkVersion = "27.0.12077973"
buildToolsVersion = "36.1.0"
defaultConfig {
minSdk = 24
targetSdk = 36
externalNativeBuild {
cmake {
cppFlags += "-std=c++17"
arguments += "-DOpenCV_DIR=${rootProject.projectDir}/opencv/native/jni"
}
}
}
buildFeatures {
viewBinding = true
}
}
app/src/main/cpp/CMakeLists.txt:
cmake_minimum_required(VERSION 3.22.1)
project("project_flam")
# OpenCV integration
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../../../opencv/native/jni")
find_package(OpenCV REQUIRED)
add_library(project_flam SHARED native-lib.cpp)
target_link_libraries(project_flam ${OpenCV_LIBS} log)
- App launches without crashes
- Camera permission request appears
- Camera preview displays correctly
- FPS counter updates (~30 FPS expected)
- OpenCV version displays correctly
- Toggle button switches between modes
- Status text updates when toggling
- Logcat shows mode change messages
- Save Frame button works
- Toast confirms frame save
- Frame saved to Pictures folder
- frame.jpg saved for web viewer
- Web viewer displays saved frame
- Web viewer stats overlay shows correct info
- App handles rotation gracefully
- App pauses/resumes camera correctly
# View all MainActivity logs
adb logcat MainActivity:D *:S
# View OpenCV/NDK logs
adb logcat OpenCV_NDK:D *:S
# View both
adb logcat MainActivity:D OpenCV_NDK:D *:S
- On Launch: Camera preview starts, FPS counter shows ~30 FPS
- Toggle OFF β ON: Status shows "Edge Detection", logcat shows "Edge detection enabled"
- Toggle ON β OFF: Status shows "Raw Camera", logcat shows "Edge detection disabled"
- Save Frame: Toast confirms save, two files created (timestamped + frame.jpg)
- IMPLEMENTATION_GUIDE.md: Detailed implementation notes, architecture diagrams, and feature walkthroughs
- TESTING_GUIDE.md: Step-by-step testing procedures with expected results
- COMMIT_MESSAGES.md: Ready-to-use commit messages for all features
- web/README.md: Web viewer setup and usage
Problem: OpenCV not found
# Solution: Verify opencv/native/jni exists
ls opencv/native/jni/OpenCVConfig.cmake
# If missing, check OpenCV module is included
./gradlew :opencv:assembleDebug
Problem: NDK not configured
# Solution: Set NDK in local.properties
echo "ndk.dir=C:\\Users\\YourUser\\AppData\\Local\\Android\\Sdk\\ndk\\27.0.12077973" >> local.properties
Problem: Camera preview black/frozen
- Check camera permission granted
- Verify emulator has camera configured (Virtual Scene for back camera)
- Check logcat for Camera2 errors
Problem: Low FPS (<20)
- Close other apps
- Use physical device instead of emulator
- Check if GPU acceleration enabled
Problem: Frame save fails
- Grant storage permission for Android < 10
- Check available storage space
- Verify app has external storage access
Problem: Frame not displaying
# Verify frame exists
adb shell ls /sdcard/Android/data/com.example.project_flam/files/Pictures/
# Pull frame manually
adb pull /sdcard/Android/data/com.example.project_flam/files/Pictures/frame.jpg web/
Problem: TypeScript compilation fails
cd web
npm install
npm run build
- β Commit #1: Initial project setup with Gradle and NDK configuration
- β Commit #2: Add OpenCV 4.8.0 Android SDK and CMake integration
- β Commit #3: Feature: Implement live camera preview using Camera2 API
- β Commit #4: Fix: Resolve OpenCV build configuration issues
- β Commit #5: Fix: Resolve MainActivity Kotlin compilation errors
- β Commit #6: Feature: Add TypeScript web viewer for saved frames
- β Commit #7: Feature: Add toggle button for raw vs edge-detected output
- β Commit #8: Feature: Add FPS counter and frame saving capability
- β³ Commit #9: Refactor: Clean up code and finalize project structure
- β³ Commit #10: Docs: Create comprehensive README with setup instructions
master
: Stable releasescopilot/implement-worker-execution-logic
: Feature development branch
This project is licensed under the MIT License - see the LICENSE file for details.
Aayush Bhure
- GitHub: @AAYUSHBHURE
- OpenCV Team: For the excellent computer vision library
- Android Team: For Camera2 API and modern Android development tools
- JetBrains: For Kotlin programming language
- Community: Stack Overflow, GitHub, and Android developer community
- Android Camera2 API Documentation
- OpenCV Android Tutorial
- CMake Android NDK Guide
- TypeScript Documentation
- Material Design Guidelines
Built with β€οΈ using Kotlin, C++, OpenCV, and TypeScript