I'm using NDK with the experimental gradle plugin, and initially I was able to debug my native code.
Then I saw this issue https://github.com/googlesamples/android-ndk/issues/119 and this blog post http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/.
This approach would be great, because I could use the stable gradle plugin for android specific code, and the experimental gradle plugin for the native code, witch would be great to use use databinding for example.
I was able to use this structure, but I lost the ability to debug native code.
I have created a sample project that illustrate my problem.
https://github.com/4brunu/AndroidNDKDebug
In there you can find two projects.
The first one "hello-jni-one-gradle-plugin", only use the experimental gradle plugin, and I'm able to debug the native code.
The second one "hello-jni-two-gradle-plugins", I use the stable gradle plugin for android specific code, and the experimental gradle plugin for the native code, and I'm unable to debug the native code.
Am I doing something wrong?
Could you help me enable native code debug in the second project please?
Thanks
I'm using the same setup in one of my projects, with Android Studio 2.1-preview5, gradle-experimental 0.7.0-alpha5, and gradle plugin 2.1.0-alpha5, and debugging works.
The secret missing step is to add the path to your non-stripped libs to the debugger: lib/build/intermediates/binaries/release/obj/ABI
Related
I have some problems in creation of native code in new version of Android Studio 3.3. In the previous versions it was easy: create a project and check the Include C++ support
But in the new version that option disappeared and everything changed. I’m trying to find how to include c++ support but I can’t. Can you help me, please
Have you tried with Native C++ option (bottom right)?
Take a look at this link: https://developer.android.com/studio/projects/add-native-code
i think they removed auto use for c++ in this version and you need to add it manually.
This has changed in the January 2019 release (version 3.3), as new projects use CMake by default:
For new projects, Android Studio uses CMake by default, but also supports ndk-build for existing projects. To learn how to include native code in your Android application, read Add C and C++ Code to Your Project. To learn how to debug native code with lldb, see Debug Native Code.
Following the link in the quote will give you an up-to-date walkthrough on how to add C++ code to your project.
I have two existing native libraries that I would like to integrate into an Android project. One has a working Android.mk file and the other has a working CMakeList.txt file. Is there a clean way to link both to Gradle?
Using CMake's ExternalProject[1] is the only idea I have at the moment.
[1] https://cmake.org/cmake/help/v3.0/module/ExternalProject.html
The solution that I arrived at was to add an additional Gradle module to build the ndk-build project. In Gradle terms the project would become a multi-project/multi-module build and is discussed further here [1]. I was also able to express the dependency in Gradle and the project built without issue.
My initial thought of using CMake's ExternalBuild failed under Gradle, but would build fine when invoking CMake from the command line. This probably had something to do with my lack of knowledge in Gradle and CMake.
[1] https://speakerdeck.com/bmuschko/state-of-the-art-gradle-multi-module-builds
I might have what you need. There is an all c++ sample that involves no JAVA UI which is actually a big thing because now your main (entry point) is in a c++ file - you can do OOP and depend on 3rd party libraries without much hassle.
Check out my repo: https://github.com/skanti/Android-Manual-Build-Command-Line
I have an Android app that uses OpenCV's Java wrapper for image processing. To add OpenCV to the project, I had to add the following line to gradle.properties:
android.useDeprecatedNdk=true
This had been working fine without any warnings or errors (that I know of) up until I updated my Android Studio and Gradle after a long time (I'm using Gradle 2.2.2 and Android Studio 2.2.2 now). Now when I build my app, I get the following warnings on the messages window:
Warning:Native C/C++ source code is found, but it seems that NDK
option is not configured. Note that if you have an Android.mk, it is
not used for compilation. The recommended workaround is to remove the
default jni source code directory by adding:
Warning:Deprecated NDK integration enabled by useDeprecatedNdk flag in
gradle.properties will be removed from Android Gradle plugin soon.
Even though the build is successful at this time, as the second warning informs, this is highly likely to cause some trouble in the future, so I want to resolve them as soon as possible before things go sideways.
Does anyone know how to get resolve these warnings? Or are there any other way to import OpenCV to an Android project, other than adding all the compiled code (the .so files) and setting the flag I mentioned earlier? Any help on this will be appreciated.
I would suggest to migrate over to using the native support with cmake. You could check the link which provides a step-by-step tutorial to add OpenCV using cmake via the following link.
You're code should stay the same without any changes, only necessary action is to figure out how to include them within the build process using CMakeLists.txt.
In the project pane, right click your app (in my React Native project it's the "app" catalog), and select "Link C++ project with gradle".
Now you must find the Android.mk file - it should be already generated in your_app/app/build/intermediates/ndk/debug/
I am trying to integrate crashlytics for android project. My project is using a subproject which is having native code in it.
Now my question is that, I want to enable ndk crash reporting also for my project.
From the docs, I understood that i need to configure the below lines in fabric properties (Im using ant as build tool):
enableNDK=true
androidNdkOut=obj
androidNdkLibsOut=libs
Since my project doesnt have direct native code, I cant specify above paths.
How can I achieve this?
I would like to use the Android Mapbox GL library for a project. I will need to modify the source, so I am attempting to include the mapbox-gl-native project source as a git submodule. I'm new to this, so if I'm on the wrong track using a git submodule, let me know that too.
Here's the project:
https://github.com/bessermt/TriMetRail
It all seems to work, but I can't get the debugger to step into the C++ source of the library with Android Studio. I suspect that since the project is only showing me the Java source files and not the C++, that is a clue to what I'm missing.
If anyone has an idea on how to do this, it would be much appreciated.
thx.
The library you reference uses the old gradle plugin:
classpath 'com.android.tools.build:gradle:1.5.0'
The experimental plugin is required today to debug native code in Android Studio. Updating all build scripts, with all the dependencies, for the new plugin may be a tricky task, so I would suggest that you post your request on GitHub.
I doubt this will make it into the android-v3.1.0 milestone.
I think use the experiment version of the gradle may fix the problem