Android library with java code
-
Hi guys!
I have a simple question that I couldn't be able yet to figure it out. I have my Android application and I want to create many library for specific functions (GPS, Network, etc). I'd like to modularize these modules into .so libraries but I'm not sure how to include my java code in a library project. Is this even possible?
I took QtNotifier as example and had no problem to add my file and make calls from C++ to Java and from Java to C++. Therefore, my question is only about .pro configuration.
I set ANDROID_PACKAGE_SOURCE_DIR and DISTFILES but there is no trace in Compile Output of my java file :/
I added some errors to this file and QtCreator doesn't even notice that the file will not compile.Could someone guide me with this problem? Am I taking a good decision about architecture of my Android application?
Thanks in advance,
Fernando -
Unless you write your Android function in JNI completely, it is not possible to bundle native Java source within .so file. Or you may build a .jar file together with .so .
-
-
You need to tell where is your Java files by configure your build.gradle .
For example, you may add your Java file path to
java.srcDirs
in build.gradlesourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java'] aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl'] res.srcDirs = [qt5AndroidDir + '/res', 'res'] resources.srcDirs = ['src'] renderscript.srcDirs = ['src'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] }