###There is no official maven-based way to install OpenCV on Android. You have to download and set it up to your project.
-
File>New>Import Module
and selectsdk/java
└── sdk
├── etc
├── java
└── native
- Go to openCVLibrary320/build.gradle, change
compileSDKVersion
to 25 and resync - Right Click at openCVLibrary320
New>Folder>JNI Folder
- Change Folder Location and type
src/main/jniLibs/
- Go to
sdk/native/libs
and copy all folders inside libs
native
├── 3rdparty
├── jni
└── libs
├── arm64-v8a
├── armeabi
├── armeabi-v7a
├── mips
├── mips64
├── x86
└── x86_64
- Paste them in the
jniLibs
folder - Remove all .a files since we only need .so files only in Android. You can manully delete it or use this command
find . -name "*.a" -type f -delete
. - Remove
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
fromopenCV320Library/build.gradle
I don't know why but including this won't make the app compile. Removing it results in a compilation successs. - Add
compile project(path: ':openCVLibrary320')
in your build.gradle of your main module. - Test if OpenCV is loaded correctly by adding
static ...
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
static {
if(!OpenCVLoader.initDebug()){
Log.d(TAG, "OpenCV not loaded");
} else {
Log.d(TAG, "OpenCV loaded");
}
}
....