> ## Documentation Index
> Fetch the complete documentation index at: https://docs.edgeimpulse.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Static buffer inference on Android

> Run Edge Impulse inference with pre-loaded test data on Android

This tutorial shows how to run an Edge Impulse model on Android using hardcoded test data with no sensors required. It's a useful starting point before moving on to camera, audio, or motion input.

## What you'll build

A basic Android app that:

* Loads a C++ model via Android NDK
* Runs inference on static test features
* Displays classification results

## Prerequisites

* Trained Edge Impulse model
* Android Studio with NDK and CMake installed
* Basic familiarity with Android development

## 1. Clone the repository

```bash theme={"system"}
git clone https://github.com/edgeimpulse/example-android-inferencing.git
cd example-android-inferencing/example_static_buffer
```

## 2. Download TensorFlow Lite libraries

```bash theme={"system"}
cd app/src/main/cpp/tflite

# Windows
download_tflite_libs.bat

# macOS/Linux
sh download_tflite_libs.sh
```

## 3. Export your model

1. In Edge Impulse Studio, go to **Deployment**
2. Select **Android (C++ library)**
3. Click **Build** and download the `.zip`

## 4. Integrate the model

1. Extract the downloaded `.zip` file
2. Copy all files to:
   ```
   example_static_buffer/app/src/main/cpp/
   ```

Your structure should look like:

```
app/src/main/cpp/
├── edge-impulse-sdk/
├── model-parameters/
├── tflite-model/
├── native-lib.cpp
└── CMakeLists.txt 
```

## 5. Add test features

1. In Studio, go to **Model testing**
2. Click on a test sample
3. Copy the **raw features**
4. Paste into `native-lib.cpp`:

```cpp theme={"system"}
// app/src/main/cpp/native-lib.cpp
std::vector<float> raw_features = {
    // Paste your raw features here
    -1.2, 0.5, 2.1, ...
};
```

## 6. Build and run

1. Open the project in Android Studio
2. **Build** → **Make Project**
3. Run on a device or emulator

You should see classification results on screen.

## How it works

### Native inference

```cpp theme={"system"}
// native-lib.cpp
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_test_1cpp_MainActivity_runInference(
    JNIEnv* env, jobject /* this */) {
    
    // Create signal from raw features
    signal_t signal;
    signal.total_length = raw_features.size();
    signal.get_data = &get_feature_data;
    
    // Run classifier
    ei_impulse_result_t result = {0};
    EI_IMPULSE_ERROR res = run_classifier(&signal, &result, false);
    
    // Format results
    return env->NewStringUTF(format_results(result).c_str());
}
```

### Java/Kotlin bridge

```kotlin theme={"system"}
// MainActivity.kt
class MainActivity : AppCompatActivity() {
    private external fun runInference(): String
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Load native library
        System.loadLibrary("test_cpp")
        
        // Run inference and display
        val result = runInference()
        resultTextView.text = result
    }
}
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Build fails with 'undefined reference to run_classifier'">
    **Cause**: Model files not copied correctly

    **Solution**:

    * Ensure all folders (edge-impulse-sdk, model-parameters, tflite-model) are in `app/src/main/cpp/`
    * Don't replace the existing `CMakeLists.txt`
  </Accordion>

  <Accordion title="App crashes on launch">
    **Cause**: Native library not loaded

    **Solution**:

    * Verify `System.loadLibrary("test_cpp")` matches your library name
    * Check Build output for compilation errors
  </Accordion>

  <Accordion title="Wrong classification results">
    **Cause**: Test features don't match model input

    **Solution**:

    * Copy features from Studio's Model Testing page
    * Ensure feature count matches model input size
    * Check feature order (x, y, z for accelerometer, etc.)
  </Accordion>
</AccordionGroup>

## Next steps

* [Keyword spotting on Android](./keyword-spotting)
* [Camera inference on Android](./camera-inference)
* [Android series overview](./android-series)
