Debug native code in Android Library
I was able to set breakpoints and debug native code in an android library on eclipse by adding the directory of the unstripped shared library/libraries to the debugger in the debug configurations dialog:
- Go to "Run" menu-> "Debug Configurations"
- Under "Android Native Application" in the left pane, select your application
- Under the "Debugger" tab click "Add..." in the "Shared Libraries" section.
- Browse to your android library project directory and add its subdirectory obj/local/armeabi.
- Apply and debug.
That seemed to work for me. Hopefully, you'll have the same luck...
Peace
How to debug native code in an Android library project?
Try the answer by Jay in my question: debug native code in Android library.
I had no time to test it by my self, but it looks promising.
Let me know if it works.
Debugging C++/Native code in Android Studio doesn't work with older Android SDK API version
In case someone has the same problem, here is the solution that works for us:
Instead of using API 23 as the minimum, set it as API 21 in the build.gradle file. This allows us to debug native C++ code.
Debug native code in Android Studio
Actually, the advertised NDK support isn't available yet, even if you download the ndk-bundle and update Android Studio to the latest version in the canary channel (1.3-preview3 as of now).
The SDK tools team said that the NDK support wasn't part of the first previews of Android Studio 1.3. However it should be out soon - they recently mentioned mid-June as a target.
update: the debugging support is out now. It wasn't the case at the time of the initial question - thanks for all the downvotes since then :) please look at donturner's answer below.
How to debug native react native libraries with Android Studio?
Have you done rnpm link
or react-native link
? Once you do that, there will be additional modules along with the app module, something like this.
You can look at all the java code in the native module and put breakdpoints , debug etc.
Native code debug is not working in Android Studio 3
First, check debug variant is selected for library.
As your build.gradle has a setting, path "src/main/cpp/CMakeLists.txt"
, it won't build I think. So set targets
, rebuild and check again.
If breakpoints doesn't work after build, old garbage may be left in the build cache and causes problems. Open project directory in explorer and delete build cache (.externalNativeBuild folder) manually and build the project again. I also delete build folder, as it contains .so files in intermediate directory, but it's optional.
Android Studio does not clean libraries in the test device. They are overwritten basically, but clear them manually depending on needs. Files are in /data/app/(package name)/lib/(cpu arch.)/.
NB: Synchronize menu of device file explorer does not synchronize properly under lib or (cpu arch.) directory. To synchronize, select /data or /data/app and choose Synchronize.
NB.1 If targets
is omitted, Android Studio seems to build no targets. The built output is in (project)/app/build/intermediates/cmake/(flavor)/obj/(cpu architecture). If it seems to work without any targets, check files on device. They confuse test results.
NB.2 debuggable true
is for release build to enable debugging. No need to set it for debug build, as debuggable flag is set as default.
NB.3 Seems version dependent but Gradle in Android Studio does not clean .externalNativeBuild tree properly even if clean or rebuild is called, and confuses native code build configs. It was around AS3.0, as I remember.
NB.4 My environment is
- Android Stuidio 3.2.1
- classpath 'com.android.tools.build:gradle:3.2.1'
- gradle-4.7-all
- CMake: default(3.6.4111459)
I know there are newer versions for Android Studio, Gradle and CMake but they are buggy, so I chose current environment. As far as I've experienced, Android Studio 3.3, gradle:3.3.0, gradle-4.10.1-all have severe bug in VCS(git). Wrong file contents are shown in editor and build fails, sometimes. Setting CMake version to 3.10.x (3.10.2 for me) also seems buggy.
Here's a copy from my project as a sample, partially modified from original one but may work.
I've checked breakpoints in a library work in Android Studio 3.2.1.
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
arguments "-DANDROID_STL=c++_static"
targets "sample"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Update
targets is mentioned here Guide - Link Gradle to your native library - Specify optional configurations.
Related Topics
Execute Task Before Android Gradle Build
How to Find Intent Source in Android
Change Background of Progressdialog
Register to Be Default App for Custom File Type
How to Rename a File on Sdcard with Android Application
Set Permission for Getting User's Email Id from Facebook Login
How to Disable All Views Inside the Layout
Difference Between Content_Main.Xml and Activity_Main.Xml
Android App Crashes with Sigabrt Signal 6 Only While Eclipse Debugging
If I Call Getmeasuredwidth() or Getwidth() for Layout in Onresume They Return 0
How to Get File Path from Sd Card in Android
Android Overlay to Grab All Touch, and Pass Them On
Uncaught Exception in Firebase Runloop (3.0.0)
Opening Webview Not in New Browser