Extra Steps must Do if your Project contains C++ files (like the native jni OpenCV)
******SEE Android official site first for details and any possible changes *****
STEP 1 Install LLDB:
If your project includes C/C++ code, you need to install LLDB from the SDK Manager.
STEP 2: Install NDK (and possibly CMake)
Here is a link (https://developer.android.com/studio/projects/add-native-code.html) on adding Native code to an Android Studio Project in general
One think you must have for debugging is the NDK and possibly CMake tools.
STEP3: Run a debuggable build variant:
-
You must use a build variant that includes debuggable true in the build configuration. Usually, you can just select the default "debug" variant that's included in every Android Studio project (even though it's not visible in the build.gradle file). But if you define new build types that should be debuggable, you must add `debuggable true` to the build type:
android {
buildTypes {
customDebugType {
debuggable true
...
}
}
}
This property also applies to modules with C/C++ code. (The jniDebuggable property is no longer used.)
Note: If your app depends on a library module that you also want to debug, that library must also be packaged with debuggable true so it retains its debug symbols. To ensure that the debuggable variants of your app project receive the debuggable variant of a library module, be sure that you publish non-default versions of your library.
STEP 4: edit your app gradel files so it has a debug buildTypes option specified--see blue for
newly added code
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.grewe.ilab.imageprocessingproject"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
externalNativeBuild {
ndkBuild {
path file('../../../../../opencv-4.0.1-android-sd/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk')
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':OpenCV401')
}
Step 5: edit your OpenCV module's gradel file to have a debug buildType as shown in blue
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"// not needed since com.android.tools.build:gradle:3.0.0
defaultConfig {
minSdkVersion 26
targetSdkVersion 28
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
jniLibs.srcDirs = ['../../jni']
java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory
aidl.srcDirs = ['src']
res.srcDirs = ['res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
dependencies {
}
Now you can run it in Debug mode