Skip to main content
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

git clone https://github.com/edgeimpulse/example-android-inferencing.git
cd example-android-inferencing/example_static_buffer

2. Download TensorFlow Lite libraries

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:
// 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. BuildMake Project
  3. Run on a device or emulator
You should see classification results on screen.

How it works

Native inference

// 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

// 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

Cause: Model files not copied correctlySolution:
  • Ensure all folders (edge-impulse-sdk, model-parameters, tflite-model) are in app/src/main/cpp/
  • Don’t replace the existing CMakeLists.txt
Cause: Native library not loadedSolution:
  • Verify System.loadLibrary("test_cpp") matches your library name
  • Check Build output for compilation errors
Cause: Test features don’t match model inputSolution:
  • Copy features from Studio’s Model Testing page
  • Ensure feature count matches model input size
  • Check feature order (x, y, z for accelerometer, etc.)

Next steps