0

I'm trying to run DNN with the help of MNN in android studio project.

What I Do:

  • I create a Native C++ project in android studio.
  • I have built libMNN.so according to the document of MNN, and place it in the directory app/arm64-v8a/libMNN.so
  • I have changed the app/build.gradle as follows
plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.mymnn'
    compileSdk 32

    defaultConfig {
        applicationId "com.example.mymnn"
        minSdk 29
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            ndk {
                abiFilters 'arm64-v8a'
            }
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            version '3.18.1'
        }
    }
    buildFeatures {
        viewBinding true
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
  • Then I can see app/jniLibs in Android View in android studio. It seems like I have import so file successfully.
  • I notice that in the MNN demo project they include MNN files by #include <MNN/expr/Module.hpp> rather than #include "MNN/expr/Module.hpp", so I think MNN/expr/Module.hpp should be compiled in the so file libMNN.so. However, I cannot import it by #include <MNN/expr/Module.hpp> in my src/main/cpp/native-lib.cpp file.

What I Wonder

As a beginner for both C++ and android project, I want to know

  • The usage of so file (does it provide some APIs that I can include in C++ header files?)
  • Does #include <MNN/expr/Module.hpp> includes Module.hpp from so file? If yes how can I inlcude it in my project?
david
  • 842
  • 2
  • 8
  • 25
  • Maybe you want to refer to [this](https://stackoverflow.com/questions/36639655/what-is-the-actual-use-of-so-file-in-android) – Abhishek Dutt Sep 30 '22 at 04:12
  • The library contains the implementation, the headers are the interface to that implementation and are separate from it, you need to configure their location separately – Alan Birtles Sep 30 '22 at 04:17
  • @AlanBirtles thanks, does that mean I need to add the header files of MNN into my project (in directory `cpp/include`), then modify `app/build.gradle` or `CMakeLists.txt` to tell the project to import these header files when building the project? – david Sep 30 '22 at 04:28
  • I suggest you follow a cmake tutorial – Alan Birtles Sep 30 '22 at 04:29
  • @AlanBirtles I mean, I have already improt so file (the implementation) in my project, so I need to import the headers files now (the interface), right? – david Sep 30 '22 at 04:30

0 Answers0