Page 1 of 1

Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 12:25 am
by redpearl
In the sample AndroidJNI (ogre/Samples/AndroidJNI), there is a MainActivity.java. I tried to build it in Android Studio. However, it cannot find libOgreJNI.so when executed. How can I generate this so file?

I can build and run the other Android sample (SampleBrowserNDK). But that one is a pure native one using NativeActivity. I would like to use the "traditional" Android way like what AndroidJNI is doing.

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 1:36 am
by paroj
did you build the Java Component? If so it should have generated an according android project in ${CMAKE_BINARY_DIR}/OgreJNI,

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 3:19 am
by redpearl
Yes. I have enabled Java component, and it generated lots of Java files. I packed them into a Jar file and used it in Android Studio. But there is no so file generated. How can I generate libOgreJNI.so?

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 10:50 am
by paroj
should be in ${CMAKE_BINARY_DIR}/OgreJNI/libs

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 6:42 pm
by redpearl
There is a folder named "OgreJNI/libs/armeabi-v7a", but it is empty.

How can I generate the so file. Can you post more detailed command line or a link? Thanks!

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 7:00 pm
by redpearl
i think I know why the so file is not generated. When I run "make OgreJNI", i got a link error saying
"ld: fatal error: -soname: must take a non-empty argument"

I see Components/Java/CMakeLists.txt has a line at the end as:

set_target_properties(${SWIG_MODULE_OgreJNI_REAL_NAME} PROPERTIES NO_SONAME OFF) # workaround for SWIG/ android interop

However, this line does not work.

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 7:48 pm
by redpearl
More search online, I realized that this "NO_SONAME" tricks works until cmake 3.3 and is ignored from cmake 3.4. Since I am using cmake 3.8, it does not work at all.

Someone suggest to replace the deprecated swig_add_module to swig_add_library. I tried to replace the line:
"swig_add_module(OgreJNI java ${SWIG_INPUT_MODULES})" with
"swig_add_library(OgreJNI LANGUAGE java SOURCES ${SWIG_INPUT_MODULES})"

However, I still get the same error when build OgreJNI. Can anyone guide how to fix it?

BTW: I found that Ogre used extremely old stuffs for Android. I have to manually download a very old version of SDK tools to make the "android" command works. Please make it suitable for the latest Android tools, particularly, Android Studio with gridle.

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 11:18 pm
by paroj
redpearl wrote:
Tue Nov 28, 2017 7:48 pm
BTW: I found that Ogre used extremely old stuffs for Android. I have to manually download a very old version of SDK tools to make the "android" command works. Please make it suitable for the latest Android tools, particularly, Android Studio with gridle.
yes, viewtopic.php?f=21&t=93782#p540045

Re: Question about AndroidJNI sample

Posted: Tue Nov 28, 2017 11:41 pm
by redpearl
Is there any way to generate the so file with cmake 3.8? The NO_SONAME trick failed for cmake 3.3+.

Re: Question about AndroidJNI sample

Posted: Wed Nov 29, 2017 1:18 am
by redpearl
I finally generated the so file using the most straightforward method -- replacing my cmake to 3.2 version.

However, it would be really nice to modify Ogre itself making it working for latest tools (cmake, NDK, etc.). Otherwise, many people will soon met the same errors and complain about it.

Re: Question about AndroidJNI sample

Posted: Thu Nov 30, 2017 11:23 pm
by paroj
this should allow using CMake 3.2+