OptaPlanner on Android
Developing of mobile applications on Android is currently very popular. One of the reasons for this popularity is Java programming language. Although OptaPlanner is written completely in pure Java (Standard Edition), the current version (6.2.0.Final) requires a workaround to work on Android due to a limitation in the Android platform. In this article, I will show how to use OptaPlanner on Android and demonstrate a simple Vehicle Routing app.
How to use OptaPlanner on Android
Update: as of OptaPlanner 6.3.0.Beta2, this workaround is no longer needed, because OptaPlanner does not import the java.beans package anymore.
Android is not a complete JVM. Some JDK libraries of the java.beans package are missing for OptaPlanner 6.2 to work out of the box.
However, it is possible to use OptaPlanner with Java score calculation by adding those missing libraries to your
Android project. The Drools rule engine does not work on Android yet, so Drools score calculation doesn’t work on Android.
If you would like to use OptaPlanner in your Android project, follow these steps:
-
Download OpenBeans redistribution of the
java.beanspackage. -
Download Jar Jar Links utility for repacking the redistribution.
-
Create a
jarJarRule.txttext file with a single line:
rule com.googlecode.openbeans.** java.beans.@1
-
Place all the files in the same folder and run the command:
$ java -jar jarjar-1.4.jar process jarJarRule.txt openbeans-1.0.jar javabeans-1.0.jar
-
Move the created
javabeans-1.0.jarinto thelibsfolder in your Android project. -
Add these lines to
androidarea in thebuild.gradlefile in your Android project to allow classes of thejava.*package inside thejavabeans-1.0.jarfile to be used:
android {
...
dexOptions {
preDexLibraries = false
}
project.tasks.withType(com.android.build.gradle.tasks.Dex) {
additionalParameters=['--core-library']
}
...
}
-
Add a dependency to the
build.gradlefile in your Android project and excludeorg.droolsandxmlpulldependencies:
dependencies {
...
compile('org.optaplanner:optaplanner-core:...') {
exclude group: 'xmlpull'
exclude group: 'org.drools'
}
...
}
Vehicle Routing Problem application
I created an OptaPlanner Android application named Vehicle Routing Problem. It is based on Vehicle routing application from OptaPlanner Examples. See this video for a detailed demonstration:
Get this app from the Google Play app store now. The source code is on GitHub.
Conclusion
Now you can create your own Android applications which use OptaPlanner. Follow the steps written above or get inspired by the mentioned example.




Comments
Visit our forum to comment