How to include missing classes in Android compile

50 views
Skip to first unread message

pw...@thevisioncouncil.org

unread,
Apr 19, 2018, 7:28:43 PM4/19/18
to CodenameOne Discussions
I'm trying to use java.util.Locale, java.util.Random, and java.util.Objects but when I try and submit an Android build it fails saying those symbols can't be found.  It seems like from the API you have those should be there so I must be doing something wrong, yeah?  I need some help.  Using Intellij IDEA and latest of everything on Windows 10.

It is exceedingly baffling that this runs in the simulator yet clearly it should not if I'm not able to submit it for a build.

Thomas

unread,
Apr 19, 2018, 10:22:06 PM4/19/18
to CodenameOne Discussions
java.util.Random is implemented. The others two are not (I don't know where you see them in the API). The reason it works in the simulator is that the simulator is using the oracle java JVM installed in your computer (that supports the full java API obviously). On devices, only parts of the java API that have been ported to CN1 will work (as CN1 do not support the full java API: https://www.codenameone.com/blog/why-we-dont-support-the-full-java-api.html) exept from Android where it will support the full android java API (So it should be possible to make an android build that uses these 2 missing (in CN1) classes as they exists in the android java API. But it is really not recommanded to use classes that are not part of the CN1 api as it would not work on other platforms like iOS. I guess the build server is watching for this whatever the build target and that is why it rejected your build...). On any IDE supporting the CN1 plugin (Netbeans, IntelliJ, Eclipse) you should see an error if you try to import a class that do not exists in the CN1 API though (so detecting unsupported imports should be trivial)

Shai Almog

unread,
Apr 20, 2018, 12:21:11 AM4/20/18
to CodenameOne Discussions
Which IDE are you using?
Did you change the build.xml or classpath?

In some of the IDE's it's harder for us to block javac from compiling against JavaSE. The simulator works with JavaSE and is oblivious to the limitations of the API.

I discussed some of the problem of supporting the full scope of the Java API here: https://www.codenameone.com/blog/why-we-dont-support-the-full-java-api.html

pw...@thevisioncouncil.org

unread,
Apr 20, 2018, 4:39:00 PM4/20/18
to CodenameOne Discussions
I did mention in my OP that I was using Intellij IDEA.  I did read your article on the Java API support as I found it when trying to research this issue.  I totally understand and appreciate the dilemma.  I was more frustrated that I was able to do a lot of development in the simulator with the expecation that my code was acceptable when it was not.  Now I have to try and refactor that class.  Specifically I don't know immediately how to replicate the behavior of Objects.requireNotNull() but I'm sure I can figure it out.  I was able to just drop the use of java.util.Locale.

pw...@thevisioncouncil.org

unread,
Apr 20, 2018, 4:40:56 PM4/20/18
to CodenameOne Discussions
Sorry, I must have made a mistake on the other two.  I'll just need to refactor and wrong my own version of Objects.requireNotNull().  I was able to drop Locale completely.  Hopefully Random behaves as expected.
Reply all
Reply to author
Forward
0 new messages