Question about AndroidJNI sample

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 12:25 am

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.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 544
Joined: Sun Mar 30, 2014 2:51 pm
x 76
Contact:

Re: Question about AndroidJNI sample

Post by paroj » Tue Nov 28, 2017 1:36 am

did you build the Java Component? If so it should have generated an according android project in ${CMAKE_BINARY_DIR}/OgreJNI,
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 3:19 am

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?
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 544
Joined: Sun Mar 30, 2014 2:51 pm
x 76
Contact:

Re: Question about AndroidJNI sample

Post by paroj » Tue Nov 28, 2017 10:50 am

should be in ${CMAKE_BINARY_DIR}/OgreJNI/libs
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 6:42 pm

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!
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 7:00 pm

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.
Last edited by redpearl on Tue Nov 28, 2017 8:32 pm, edited 1 time in total.
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 7:48 pm

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.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 544
Joined: Sun Mar 30, 2014 2:51 pm
x 76
Contact:

Re: Question about AndroidJNI sample

Post by paroj » Tue Nov 28, 2017 11:18 pm

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
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Tue Nov 28, 2017 11:41 pm

Is there any way to generate the so file with cmake 3.8? The NO_SONAME trick failed for cmake 3.3+.
0 x

redpearl
Gnoblar
Posts: 17
Joined: Tue Nov 28, 2017 12:19 am

Re: Question about AndroidJNI sample

Post by redpearl » Wed Nov 29, 2017 1:18 am

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.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 544
Joined: Sun Mar 30, 2014 2:51 pm
x 76
Contact:

Re: Question about AndroidJNI sample

Post by paroj » Thu Nov 30, 2017 11:23 pm

this should allow using CMake 3.2+
0 x

Post Reply