I am following this guideline to compile a c++ project.
It compiles successfully (it shows *[100%] Built target MY_SERVICE).
I can also observe that, it generates *.so library files.
After defining the output directory i can see a file with MY_SERVICE name without any extension.
MY_SERVICE is defined in CMAKELists.txt as below
set(BIN_TARGET MY_SERVICE)
My question is that what is the next step and how i can run it on an android platform.
Related
I have a Java Library project in my AOSP build which creates a jar file and hosts it in system/framework
Everything works as expected, however I now wish to create a JAR file from the same library to allow and application to link and compile against it. Goal is to be able to create APKs against this lib (compileOnly) so that the APK can run and use the library on the ROM.
The problem is that Jack seems to be generating only dexed jar files which cannot be used in Android Studio as libraries.
Is there a way to disable DEXing in the Android.mk ?
I know there is an option in Android.bp (cannot recall it) which gives the option for the build to generate normal jar (with .class files).
Note: I cannot use BUILD_DROIDDOC with stubs due to enviroment issues (custom ROM) assuming BUILD_DROIDDOC is only executed with lunch sdk-eng
This is for a custom ROM with Android 8.1 base. I think the custom option of not dexing in Android.dp file is not supported in this version anyway.
I am integrating existing C++ code that uses OpenCV to an Android app, using Android studio. For this purpose, I have installed the package OpenCV-android-sdk and added it as a module to Android studio. I have also created a simple Kotlin app.
So far I have managed to integrate my C++ code into the project. After adding the paths to the OpenCV includes by means of an include_directories statement, the code compiles successfully.
My next step would be to link against the precompiled OpenCV library, to resolve the "undefined symbol" errors. I have no idea how to achieve this/where to specify it. I have tried to find resources on the web, but not two resources tell the same and the solutions seem overly complicated. I am lost in the jungle.
I finally managed. Here comes the recipe (validated under Windows).
Make sure to download the OpenCV Android SDK and copy it somewhere.
The project must be created as a Native C++ app (Phone and tablet). A cpp folder is automatically created with a native-lib.cpp source file and a CMakeLists.txt.
Add the following lines to the CMakeLists file, after the project line:
set(OpenCV_DIR $ENV{OPENCV_ANDROID}/sdk/native/jni)
find_package(OpenCV REQUIRED)
You must define the environment variable OPENCV_ANDROID and make it point to the folder .../OpenCV-android-sdk that you copied. (Alternatively, you can hard-code the path in the set command.)
Then insert at the bottom
target_link_libraries(app_name ${OpenCV_LIBS})
where OpenCV_LIBS points to the folder .../OpenCV-android-sdk/sdk/native/libs, and app_name is the name you gave when creating your app.
Finally, cross fingers and build.
I am trying to build a Native (C++) share library in Android studio (it will be linked to another project). I created the Native project, but whatever I try, it seems I have to have at least one java file that calls a C++ API from that library, meaning I need another C++ file in my set of native files containing the function the Java file calls.
I do not want this additional file, because it will be part of the shared library. I just want to create a shared library. Any idea how to do it, or should I switch back to ndk_build and its set of makefiles?
Thanks.
you can implement that by using cmake in android studio, refer to the url of here : https://developer.android.com/studio/projects/configure-cmake
add c++ source file you needed to the directory where you want
modify the script in CMakeLists.txt to add the library you want to build:
add_library(
anyLibName
STATIC (or SHARED)
absolute path of some c++ source file
)
3.include the c++ header files:
include_directories(directory absolute path of your c++ headers file)
4.execute 'Sync' and 'Run app' in AndroidStudio's menu
5.after build finished,you can find the library(*.so or *.a) in the directory below:
{project dir}/app/build/intermediates/cmake/debug
attention that the library you build does not linked to any other library but only the c++ standard. if you want to do that you can using 'target_link_libraries' command
I want to add my own jar into the AOSP. For that I have created Android.mk make file with the command include $(BUILD_JAVA_LIBRARY). I have also added the library name under build/target/product/core_minimal.mk (Product_boot_Jar section).
My issue: With the mm command I can see the jar under system/framework/myOwn.jar (Built successfully). But with complete make command it is unable to copy myown.jar into /system/framework.
Any idea on why it is not working within Android M?
I have been trying to implement the API for the serial port found the the below web page. I am a beginner in all this and I am sure about what I am looking at:
http://code.google.com/p/android-serialport-api/source/browse/#svn%2Ftrunk%2Fandroid-serialport-api%2Fproject%2Fjni
Questions:
1) The .c files are built how? Do I need to download the NDK? I assume the .c file is run directly by the virtual machine, or what? Or is the executable for the .c the file in the libs directory? If so, how do I utilize the libserial_por.so file?
Thanks!
The .c files are built into a library by running ndk-build in the project directory. You need the NDK.
The .c files are not run directly by the virtual machine, but rather a library is created in the libs directory, which is then loaded along with the SerialPort class.
To use the library, just use the SerialPort class which already has bindings to the library.
C files will be compiled to an ARM binary library with the extension .so by the NDK. Take a look at the NDK Documentation, section "Getting Started with the NDK", to find out how to use it.
Basically, you place your .c files in the jni directory, change Android.mk to specify how to compile them, then run ndk-build to build the library. The resulting lib<name>.so will be placed in the lib directory. You then use your library in the Java project with System.loadLibrary('<name>').
This of course means the library must have a JNI interface for you to be able to use with the Java application, since Android doesn't support JNA yet.
I see though that the code you pointed out is an Android project. To run it, simply run ndk-build in the project directory to build the library, then run the project in an emulator.