Getting error while trying to build javarosa using IntelliJ IDEA

I am getting the following errors when I trying to run the gradle task build .I have my encoding set as UTF -8 .Is there something specific to this compileJava that I am missing ?

Task :compileJava FAILED
D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\model\Constants.java:23: error: unmappable character (0x9D) for encoding windows-1252

  • “int enumâ€? fields.
    ^
    D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\CodeTimer.java:37: error: unmappable character (0x9D) for encoding windows-1252
    • @param operation the name of the operation, such as “parsing formâ€?
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:130: error: illegal character: '\u201d'
      double Δλ = toRadians(p1.longitude - p2.longitude);
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:130: error: illegal character: '\u00bb'
      double Δλ = toRadians(p1.longitude - p2.longitude);
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:130: error: not a statement
      double Δλ = toRadians(p1.longitude - p2.longitude);
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:131: error: illegal character: '\u2020'
      double φ1 = toRadians(p1.latitude);
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:132: error: illegal character: '\u2020'
      double φ2 = toRadians(p2.latitude);
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u2020'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u2020'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u2020'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u2020'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u201d'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: illegal character: '\u00bb'
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^
      D:\ODK_OS\javarosa\src\main\java\org\javarosa\core\util\GeoUtils.java:133: error: not a statement
      return acos(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(Δλ)) * EARTH_EQUATORIAL_RADIUS_METERS;
      ^

Hi @neal0892! The error message says "for encoding windows-1252" so that suggests to me that the system-level encoding is not UTF-8.

Could you try changing it either through the GUI or through the command line and see if that helps?

Hi @LN Thank you for the reply.
I am still receiving the error.I think there is something peculiar to the compileJava Task in gradle build file of javarosa.
For example, It is giving me error for the greek letters in the following lines in the GeoUtils.java file:
private static double distanceBetween(LatLong p1, LatLong p2) {
double Δλ = toRadians(p1.longitude - p2.longitude);
double φ1 = toRadians(p1.latitude);
double φ2 = toRadians(p2.latitude);
But If I copy same lines to a different project,and do a normal compile , it runs without errors.
I suspect something in the task compileTask that is overriding the encoding ?

That's very strange indeed. I don't have access to a Windows dev environment to try things. Have you explored any of the ideas at https://gist.github.com/rponte/d660919434d094bbd35a1aabf7ef1bf0?

Hey @LN,
Thanks....!!
Check this out.
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
3:43:58 PM: Task execution finished.

Explanation:
When not setting the compiler encoding option explicitly, the problem you can run into is, that the Java compiler uses a different file encoding (in Gradle's case the system's default encoding) than the source code files are encoding in.
It happened to me that I had my Java code files encoded in UTF-8, Intellij IDEA compiling with UTF-8 during development (simply because it's faster), but Gradle compiling with the platform default encoding (e.g. Cp1252).

1 Like

That's great, @neal0892! How about submitting a pull request to set the encoding in the gradle file so that others don't run into these issues? You can learn more about submitting a pull request at https://github.com/opendatakit/javarosa/blob/master/CONTRIBUTING.md

1 Like

Sure @LN.Pull Request raised.