Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go Native: Integrating Native Code on Android

Go Native: Integrating Native Code on Android

Sérgio Marques Moura

July 10, 2018
Tweet

More Decks by Sérgio Marques Moura

Other Decks in Programming

Transcript

  1. Why native code? ➔ Java is slow ◆ Arithmetic tasks

    ◆ Image processing ➔ Gradle support ◆ Cmake ◆ ndk-build ➔ Research teams do it native ◆ C/C++
  2. Why compiling native code? ➔ Multiple devices ◆ Wide range

    of CPUs • Multiple instruction sets ➔ Solution: ABIs (Application Binary Interface) ◆ armeabi-v7a ◆ arm64-v8a ◆ x86 ◆ x86_64
  3. android { ... defaultConfig { ... externalNativeBuild { cmake {

    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } externalNativeBuild { cmake { path 'src/main/jni/CMakeLists.txt' } } }
  4. public class NativeDetector { static { System. loadLibrary("GlareBridge"); } public

    native double[][] detectGlare(byte[] imageData, int width, int height, int rectWidth, int rectHeight, int rectLeft, int rectTop, int numRows, int numCols); } new NativeDetector().detectGlare( … );