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 »

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.

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

Re: Question about AndroidJNI sample

Post by paroj »

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

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

Re: Question about AndroidJNI sample

Post 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?

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

Re: Question about AndroidJNI sample

Post by paroj »

should be in ${CMAKE_BINARY_DIR}/OgreJNI/libs

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

Re: Question about AndroidJNI sample

Post 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!

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

Re: Question about AndroidJNI sample

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

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

Re: Question about AndroidJNI sample

Post 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.

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

Re: Question about AndroidJNI sample

Post 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

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

Re: Question about AndroidJNI sample

Post by redpearl »

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

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

Re: Question about AndroidJNI sample

Post 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.

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

Re: Question about AndroidJNI sample

Post by paroj »

this should allow using CMake 3.2+

Post Reply