Android studio 1.4 Library module with JNI - android-studio

I'm trying to create an android module with JNI in android studio, but all the documentation I found is for older versions of android studio that did not officially support JNI. So, what is the correct way to create Library module with JNI in Android studio 1.4?

It is exactly same as with 'com.android.model.application'. Everything seems to work fine except that for me, native debugging required running NDK build steps in the app module.

Related

Does Android Studio support Code completion for C/C++?

The code completion is fine on Android Studio java project. But I want to use Android Studio to edit some existing C file(.cpp).
for example, if i have declared some function, then i type the function in other section. But the android studio doesn't show up the code suggestion or some debugging.
Can Android Studio support Code completion for C/C++ like this:?
Yes it does, as long as the project is setup to use the NDK and the C/CPP sources are included in the project.
Try pulling the ndk sample repo and try opening one of the projects.
If you have a java project and want to edit some arbitrary C or C++ source, then no. It does not have enough information about the source file, include paths, compiler etc...
If your project uses Android.mk to build, it will be a bug of Android Studio. I have been reported.
Android.mk project cannot show code completion for cpp.
It seems that old version of Android Studio does not support code completion of jni native build (with Android.mk as configuration file), and that should already be fixed now.
But if you are using CMake in your project as external building tool and code completion still does not work, It's probably because you have more than one version of cmake installed. You can try to remove extra ones from SDK manager and restart Android Studio, it should work.
To see installed CMake version, you can open the SDK manager and check the 'show package details' on the right bottom. You can view cmake tools installed with different versions.

Configure android ndk for android studio code suggestion

I'm new to android NDK and just know how to use native code in an java project as in this tutorial: http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/
But when writing in C++ the IDE features for code completion, suggestion and other stuff disappear, while in java those features work as usual.
I tried to import some ndk sample from google, they are all written in C++ instead of calling native code from JNI as I'm doing, and the projects support code completion.
Can anyone show me a way to configure Android Studio for code completion to work when developing with NDK and JNI?

android studio 2.1 issue with NDK

I am trying to use AndEngine with Android Studio 2.1 and I am running issues specifically with the NDK stuff. The version of AndEngine I am trying to use is the GLES2-AnchorCenter for reference. I create my project and add AndEngine as a module, then give my project a dependency on my AndEngine module. What I end up with is an issue with native code, specifically in in GLES20Fix.c. I get an error message about openGL ES2.0 specific stuff:
Error:(8) undefined reference to `glVertexAttribPointer'
Error:(12) undefined reference to `glDrawElements'`
I know this topic has come up before and I have read this article on the subject but that's what I was already trying to follow and that uses an older version of Android Studio that has a different import option I do not have in 2.1. I have also checked and the NDK plugin for android studio is installed and my minimum build target is over SDK level 9.
One strange detail: when I tried importing andengine as a library in eclipse it worked okay. I don't want to rely on that because I know eclipse is no longer supported for android developer tools so I want to switch off it to the newest version of Android Studio.
Can you try adding
ldLibs.addAll(['EGL', 'GLESv2'])
eg. https://github.com/googlesamples/android-ndk/blob/master/Teapot/app/build.gradle
I had the same issue. This answer helped me.
I just needed to add the following to build.gradle:
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDir 'libs'
}
}
and then rebuild the project.

Finding NDK on my System

I am following this tutorial and am stuck on Step 3 where I have to add in the NDK. What exactly is the NDK and where do I find it?
http://blog.guillaumeagis.eu/setup-andengine-with-android-studio/#comment-1535
You can also download the NDK using the SDK Manager I believe. There should be an option that says Android SDK and you can download it from within Android Studio if you are using it
what is Ndk?
Ndk is a toolset which would enable you to implement parts of your app into native languages such as C or C++.
where you can download it?
http://developer.android.com/ndk/downloads/index.html
NDK is the Android Native development kit. You can download it from here.

Add reference to CMake project in Android Studio

In my particular case, I implemented a cross platform project in C++11 that uses CMake. I initially designed this project to work on PC (Windows, Unix), but now I realized that I can use it on mobile platforms too, without re-implementing the business logic on every platform. The project uses standard libraries: Boost, Poco, OpenSSL, Protobuf.
After a few searches I came to conclusion that this is not even an usual mode to put together native and managed code in Android.
Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?
Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?
If it is possible, is it recommended at all?
Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?
Since Google announced Android Studio 2.2 that comes with cmake plugin, so it's possible to reference CMake project to android project.
Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?
In my experience, i compile NDK in separate way and then link the static/shared library (.so file) to be used in android project. I used NDK while developing PDF Reader using mupdf here
Hope this helps.
it would be possible with android studio 2.2, mainly the android plugin for gradle makes it possible. you could look at some examples in:
https://github.com/googlesamples/android-ndk/tree/master-cmake
android studio directly reads-in your cmake scripts -- there is nothing like desktop systems that generate project files for their native IDEs ( Visual Studio or XCode ); so you might have to modify your existing cmake files to eventually make it to work for android studio.
as long as you build to the correct APK, command line or IDE does not matter too much. If you intend to ship source code, having your project ready with an IDE would be attractive.
Please see CMaker_Boost, build the Boost with the CMake at a configure time. Now it is tested on the Linux and Android, gcc and clang. This can be included to the gradle project in the Android Studio. I hope this helps.

Resources