I have gone through this opencv Android samples link. In this link all the projects has a JNI C++ code which builds the ".so" file automatically and build the project. I need to create a sample project like the above examples, in which the C++ code builds automatically.
I have gone through few tutorials like this, which has steps to build JNI using command line but there is no steps to build it automatically/using eclipse project.
Can any one list out the steps to create a project in eclipse that builds JNI C++ files automatically?
I suggest you can read the article Getting Started with JNI on Android, Windows and Mac. You just need to right-click on your project and select Add Native Support. Then the IDE will automatically build the .so when you save all changes.
Related
I have a native (c++) android lib that I build in Android studio and this lib has an extension .arr. I need to use this lib in Unity as android plugin. So, I would like to clarify what is the correct way to connect this lib with Unity.
As far as I understand it should be like this:
Create c# script
Create Unity native plugin (actually it Visual Studio dll lib project)
Connect this native plugin with my native lib that I build in Android Studio
If I miss something here?
Maybe You be more specific according to the Unity Docs
To add an AAR plug-in to your Project, copy the .aar file anywhere within the Assets/Plugins/Android/libs path, then select it in Unity to open the Import Settings in the Inspector
window. Enable the Android checkbox to mark this .aar file as compatible with Unity
So Provided your .arr is ready at hand it should be easy peasy
I have a Java Android project that includes JNI code written in C.
I often need to debug into the native code and before upgrading Android Studio to version 3.3 it was working.
Now in my project view I don't have any code in my cpp folder. I have confirmed that all of the C libraries are in the folder on my HDD. The CMAKE file is also missing from the project view but is also in the correct place on my HDD.
I have not changed any code from my source control since upgrading.
I am using
'com.android.tools.build:gradle:3.3.0'.
In the Build Variants section next to my JNI module I just have five dashes instead of the debug/production options.
I have uninstalled and reinstalled android studio too.
Is it possible after upgrading I need to add something to my configuration to correct including CMAKE?
I had the same issue, just figured it out. In AndroidStudio 3.3.1, they changed things around a bit I guess. Now you have to link your NDK build to the app you are building it as part of.
This is documented at: https://developer.android.com/studio/projects/gradle-external-native-builds
The section, "Use the Android Studio UI" is what you want.
I am building an open source lib C/C++ for Android development using Android NDK. I had got code from Github and created my own jni folder under source code. In that jni folder, I created some C source files and included many header files in open source lib. But when I built, I had got failed log:
fatal error: bits/libc-header-start.h: No such file or directory
I checked and saw that file "libc-header-start.h" existed in /usr/include/x86_64-linux-gnu/bits/ folder of Ubuntu system but when building, it can not link to that header file
So can I use Ubuntu system header file in my Android NDK lib?
No, you should not use Ubuntu (or any other host) includes or libs to build an Android NDK library. NDK cross-compiles your code for the Android targets. Not all C++ projects on GitHub may be ported easily to Android. If they use CMake, these scripts often need adaptations for Android NDK. If they use automake tools, tuning the build scripts may be quite painful.
So can I use Ubuntu system header file in my Android NDK lib?
NO. You have to use all the Android NDK specific headers and libs for your NDK compilation, i.e. those inside your NDK folders.
Here is an example for Android JNI programming: https://github.com/russell-shizhen/JniExample
I have libGDX projects on one laptop. I need to move to another laptop. I am using eclipse on both windows laptops. I have a git repo I can push to and pull from. I know that I can clone the https://github.com/libgdx/libgdx-demo-cuboc and import it into eclipse as a gradle project. But when I try this with my libGDX projects the "Build Model" fails.
I suspect I did not export the project correctly from my source laptop.
Can someone please point out what I am doing wrong?
Update:
OK. When I exported the projects from Eclipse I exported as plain old Android projects (Export Android Application), so I figured that I should export the project as Generate Gradle build files but I get this error when I attempt to do so ...
... and yes I did this too ...
... and I still get the same error.
UPDATE: After accepting JH's answer. Thank you for your answer BTW.
I was able to copy files in the project, but with gradle one copies the files into the directory libGDX generated the base project. I was coping the files into my Eclipse workspace, which is why the files were not showing up in my Eclipse project ... I know confusing huh. Well I was able to get my project to build but whenever I launched the app if crashed at runtime (see java.lang.UnsatisfiedLinkError: Native method not found: com.badlogic.gdx.backends.android.AndroidGL20.glGenTexture:()) I decided to give up on Eclipse and migrate my project to Android Studio. After taking a quick look at the Android Studio I was FINALLY able to build my app and execute it without runtime errors on my new laptop!
For clarity here is what I did to migrate my project from one laptop to another.
1) I got the my code out my git repo.
2) I downloaded the latest gdx-setup.jar, 1.5.3, from the libgdx project.
3) I generated a project, being careful to use the correct values for: Name, Package, Game class and Android SDK. For Destination I used c:\Users\Me\.
4) I copied the directories android, core, html, desktop and ios directories from my git repo into the corresponding directories in the project that gdx-setup.jar created.
5) Then I started Android Studio and follow the directions found here: Migrating to Android Studio
6) updated my build.gradle to include google play service and BANG! it worked
You shouldn't have to export anything, just clone the git repository on the new computer and then import gradle project and build model.
You could even generate a new libgdx project with their project wizard and then copy the source files.
I am thinking how to get Android' s support library to include and compile outside Eclipse. I am using Linux as my build environment and I am not using any IDE for creating apps, only the basic Android SDK. I have only come over answers to this question regarding Eclipse, but how can I do it using only Ant and Android SDK?
Assuming that you are not using GridLayout:
Step #1: Copy android-support-v4.jar or android-support-v13.jar from your SDK into the libs/ directory of your project.
Step #2: There is no step #2.
Choose android-support-v13.jar if you are using native fragments (versus the Android Support package's own backport) and you want to use them with things like ViewPager that are part of the Android Support package.
GridLayout makes things a bit more complicated, in that it is an Android library project. You would need to follow the instructions for how to use an Android library project in a command-line project, probably working off of a copy of the official project.
All of this stuff can be found in the extras/ directory of wherever your SDK is installed.
Similar to this automation article http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html
Make sure to generate a valid build.xml file for ant/android building android update project --path /path/to/project
then just ant clean debug
You can also checkout the official doc http://developer.android.com/tools/building/building-cmdline.html