Integrating Native Bullet for Android in Engine Ant Build Script

Yeah, and its meant to be like that. jbullet performs terrible on android so it makes no sense using it there. As the native bullet version will always have all the api of the jbullet one both versions can be replaced. Thanks for testing! Should probably do something about that loadLibrary issue…

I was just editing my post to say I didn’t think about if your plan was to always use native. I would agree with you.



Is the loadLibrary issue as simple as uncommenting it in the PhysicsSpace.java file?

Okay, I added the loadLibrary statement to the AndroidHarness class, with a catch for when its not available. Looks like we got this working :smiley:

@iwgeric said:
Is the loadLibrary issue as simple as uncommenting it in the PhysicsSpace.java file?

Thing is the user might instantiate things like collision shapes etc. before using the physics space.
1 Like

Gotcha. I can test it again tomorrow after the nightly runs again.



Now I can remove my custom build.xml that gets around the mobile/libs directory being deleted each clean-and-build :slight_smile:



Thanks again for making the changes. Do you know when the next stable update is coming?

1 Like

Well I guess I’ll push these changes soon if they are working…

1 Like

Hey, I now added automatic starting of the app and the device log should be shown in the SDK while the application runs on the device, can you check if these changes work? Should be in the nightly tomorrow, else you can also temporarily replace all ant targets in mobile-impl.xml with this:

[xml] <condition property="android-adb-name" value="${file.separator}platform-tools${file.separator}adb.exe" else="${file.separator}platform-tools${file.separator}adb">

<os family="windows" />

</condition>



<target name="run-android" depends="-flag-no-android, jar, -test-android-enabled, -copy-android-libs" if="is.android.enabled">

<echo>Building debug android application version.</echo>

<ant dir="mobile" target="debug"/>

<antcall target="-start-android-device"/>

<ant dir="mobile" target="installd"/>

<antcall target="-run-android-device"/>

</target>



<target name="clean-android">

<ant dir="mobile" target="clean"/>

</target>



<target name="-mobile-deployment" depends="-test-android-enabled, -copy-android-libs" if="is.android.enabled" unless="no.android.build">

<ant dir="mobile" target="release"/>

<copy todir="dist" verbose="false" flatten="true">

<fileset dir="mobile/bin/">

<include name="**/*.apk"/>

</fileset>

</copy>

</target>



<target name="-copy-android-libs" if="is.android.enabled">

<!–property name="libs.jme3-android" location="${libs.jme3-android.classpath}"/–>

<echo>Copying application libraries to android project.</echo>

<delete dir="mobile/libs" failonerror="false"/>

<mkdir dir="mobile/libs"/>

<copy todir="mobile/libs" verbose="false" flatten="true">

<fileset dir="dist/lib/">

<exclude name="jMonkeyEngine3.jar"/>

<exclude name="jME3-lwjgl-natives.jar"/>

<exclude name="jME3-bullet-natives.jar"/>

<exclude name="jME3-jbullet.jar"/>

<exclude name="jME3-bullet.jar"/>

<exclude name="jbullet.jar"/>

<exclude name="stack-alloc.jar"/>

<exclude name="vecmath.jar"/>

<exclude name="lwjgl.jar"/>

<exclude name="jinput.jar"/>

</fileset>

</copy>



<echo>Adding jMonkeyEngine3.jar for android.</echo>

<copy todir="mobile/libs" flatten="true">

<!–mapper type="flatten" from="jMonkeyEngine-android.jar" to="jMonkeyEngine.jar"/–>

<path>

<pathelement path="${libs.jme3-android.classpath}"/>

</path>

</copy>

<antcall target="-unzip-bullet-libs"/>

<copy file="${dist.jar}" todir="mobile/libs/" verbose="false"/>

</target>



<target name="-delete-bullet-libs" depends="-test-bullet-included" unless="bulletIsIncluded">

<delete file="mobile/libs/jME3-bullet.jar"/>

<delete file="mobile/libs/jME3-bullet-natives-android.jar"/>

</target>



<target name="-unzip-bullet-libs" depends="-delete-bullet-libs" if="bulletIsIncluded">

<echo>Replacing bullet library with android native version.</echo>

<unzip src="mobile/libs/jME3-bullet-natives-android.jar" dest="mobile/libs"/>

<delete file="mobile/libs/jME3-bullet-natives-android.jar"/>

<delete dir="mobile/libs/x86"/>

</target>



<target name="-test-bullet-included">

<condition property="bulletIsIncluded">

<contains string="${javac.classpath}" substring="bullet.jar"/>

</condition>

</target>



<target name="-start-android-device">

<property file="mobile/local.properties"/>

<exec executable="${sdk.dir}${android-adb-name}" failonerror="true">

<arg value="start-server"/>

</exec>

<echo>Waiting for device to be ready… Connect your device or start the emulator if not done yet.</echo>

<exec executable="${sdk.dir}${android-adb-name}" failonerror="true">

<arg value="wait-for-device"/>

</exec>

</target>



<target name="-run-android-device">

<property file="mobile/local.properties"/>

<exec executable="${sdk.dir}${android-adb-name}" failonerror="true">

<arg value="logcat"/>

<arg value="-c"/>

</exec>

<exec executable="${sdk.dir}${android-adb-name}" failonerror="true">

<arg value="shell"/>

<arg value="am start -n ${mobile.android.package}/.MainActivity"/>

</exec>

<echo>Logging android device output, cancel build or stop device to stop logging.</echo>

<exec executable="${sdk.dir}${android-adb-name}" failonerror="true">

<arg value="logcat"/>

<arg value="-s"/>

<arg value="AndroidRuntime:E"/>

<arg value="System.out:I"/>

<arg value="System.err:W"/>

<arg value="NSLog:
"/>

</exec>

</target>



<target name="-test-android-enabled">

<condition property="is.android.enabled">

<istrue value="${mobile.android.enabled}"/>

</condition>

</target>



<target name="-flag-no-android">

<property name="no.android.build" value="true"/>

</target>[/xml]

1 Like

No that looks fine actually. The logging ends when the phone is disconnected or the emulator is quit or the build is canceled. Theres actually a hint about that in the log but I guess it goes by too fast.

I actually saw the hint. Just wasn’t sure. Are you supposed to be able to see the log somewhere?

I tested it.

It worked fine when i changed this line

[xml]

<ant dir=“mobile” target=“installd”/>

[/xml]

to this one

[xml]

<ant dir=“mobile” target=“install”/>

[/xml]



also I had to change the name of the main activity in the build file so the program starts (my main activity is not called MainActivity, you should have guessed it with your mind reading ability :D)



the logging looks ok but i have system.out and system.err in the console output, and all the “real” logging can’t be seen unless i open the nbandroid plugin adb logcat.

I don’t know if that’s intended though.



Anyway nice work, as always :wink:

@nehon said:
It worked fine when i changed this line
to this one

Update your Android SDK :P
@nehon said:
the logging looks ok but i have system.out and system.err in the console output, and all the "real" logging can't be seen unless i open the nbandroid plugin adb logcat.
I don't know if that's intended though.

I see all logging output of the jME3 application in the output window of the SDK. What do you mean by "real" log?

By “real” log i mean log actually output with a “logger.log(…)” method.

and exceptions.



Maybe the nbandroid plugin is catching the logs and prevent them to display in the console…

I still don’t know what you mean, in @iwgeric’s log theres messages from jme3 logging and in my emulator run tests there seemed to be as well…? But you might be right, I don’t have the NBAndroid plugin installed in my dev SDK atm…

Aahh… Now I get it (been chatting with nehon). Didn’t see that the log is from NBAndroid log cat… Maybe you can check the last exec in “-run-android-device” and change the options somehow? I cannot test this as I can only get it to throw an exception about the app not being started…

Okay, @nehon got it. I removed the “-s” parameter. Next nightly should have this in, I guess it can be moved to stable in the next update too then.

You’re right that my logging was only in NBAndroid. If you tell me where to remove the -s I’ll see if the log shows up in the application output window.

In the last “exec” in the “-run-android-device” target, just remove the whole “arg” line with the “-s”

It’s working for me now.

It looks like the activity name is hard coded to .MainActivity. Is that right? Is it intended for users to rename the main activity to something else?

Not really, its better the main activity name has a default. The application name can be set in the manifest afaik.

Your correct about the app name. It’s actually a string in the mobile/res/values/strings.xml file that AndroidManifest.xml references for the app name.



I think the run and log are good changes btw. Thanks.



Did you ever consider changing the name of the mobile project so that they all don’t have the same project name “mobile” in the platform?