2

I'm trying to build Android Permission Explorer from source code. I checked out with svn checkout http://android-permission-explorer.googlecode.com/svn/. I added a basic build.xml after checkout to the project, and then dropped into a terminal:

$ /usr/local/bin/ant release
...
-compile:
    [javac] Compiling 14 source files to .../android-permission-explorer/bin/classes
    [javac] .../android-permission-explorer/src/com/carlocriniti/android/permission_explorer/ApplicationDetail.java:7: error: unmappable character for encoding UTF-8
    [javac]  * Activit� d'affichage du d�tail d'une application
...

The error is unmappable character for encoding UTF-8.

Here's the offending line in ApplicationDetail.java (which makes no sense to me since its a comment):

/*
 * Projet   : Permission Explorer
 * Auteur   : Carlo Criniti
 * Date     : 2011.06.10
 * 
 * Classe ApplicationDetail
 * ActivitÈ d'affichage du dÈtail d'une application
 * avec les permissions qu'elle utilise
 */

There are multiple errors like this. If /usr/local/bin/ant release 2>&1 | grep -i error | wc -l is accurate, then there's 103 of them.

Question: Why are characters in the comments affecting the build?

I've been through ant's documentation at Writing a Simple Buildfile and Property Task, but damn if I can figure out how to set a source file language.

Question: How do I set the source file language in build.xml?

jww
  • 97,681
  • 90
  • 411
  • 885
  • possible duplicate of [Java, Ant error: unmappable character for encoding Cp1252](http://stackoverflow.com/questions/23399865/java-ant-error-unmappable-character-for-encoding-cp1252) – Valeri Atamaniouk Feb 14 '15 at 22:55
  • Thanks Valeri. I'm on OS X and not Windows, so I'm not using CP1252. Instead, I'm using UTF-8. Also, I'd like to know why comments are affecting the build. That makes no sense to me since they should not be interpreted in any way. – jww Feb 14 '15 at 23:09
  • It doesn't matter which encoding is used. When the compiler encounters an invalid character sequence - it is an error. So if you are sure those characters are only within comments - replace those with spaces. It would not affect resulting code in any way. – Valeri Atamaniouk Feb 14 '15 at 23:13
  • @jww The compiler has to understand the comment characters to know whether they're end-of-comment markers. – user253751 Feb 14 '15 at 23:16
  • @jww What encoding is the source file using? Set javac to use that encoding. – user253751 Feb 14 '15 at 23:17
  • @immibis - I don't mean to sound argumentative, but I've written these front end parsers (I took a compiler theory class in college). The preprocessor only needs to recognize the start and end lexemes (it could get fancy an use a stack for state and understand nested comments, but ...). It has no need to do anything other than skip stuff in between the start and stop lexemes; and ignore anything it does not understand since it can't be a start or stop lexeme. – jww Feb 15 '15 at 20:38
  • @jww in general, you can't do that without at least decoding all the characters in between. (you can *in the specific case of UTF-8*, but the compiler might be more general than that) – user253751 Feb 15 '15 at 21:01

2 Answers2

1

Even if they are in comments, invalid characters will cause a compiler error: source code is usually pre-processed before transforming to bytecode and the compiler has just encountered a character that is not mapped to its character set.

The simplest way is to edit the source files and save thm in UTF-8 encoding. Since it is a comment, it probably won't hurt to just remove the character as well.

M A
  • 71,713
  • 13
  • 134
  • 174
  • Thanks @manouti. Is there a way to get Ant/Java to ignore characters in the comments (modulo the start and end comment characters)? This is quite useless behavior, and I don't want to fix tens or hundreds of source files. – jww Feb 15 '15 at 20:28
  • @jww which character encoding is the source file encoded with? – user253751 Feb 15 '15 at 21:01
  • @immibis - sadly, I don't know which character encoding is the source file was encoded with. I'd like to change something in the `build.xml` file, but I don't know what setting that would be in `build.xml`, and I don't know what character set to use. About all I have been able to do is file a bug report at [Compiling the source files is dependent upon a particular character set](https://code.google.com/p/android-permission-explorer/issues/detail?id=2). – jww Feb 15 '15 at 21:08
  • @immibis - again, I don't know. I am a typical [ignorant] American, and I only read and write US english. It looks like it displays properly everywhere to me :) – jww Feb 15 '15 at 21:12
  • @jww I don't think the compiler can ignore comments. Could you try specifying the encoding in the javac, using something like `javac -encoding ISO-8859-1 ...` (substitute ISO-8859-1 with the actual encoding)? I never used osx but you can see http://stackoverflow.com/questions/539294/how-do-i-determine-file-encoding-in-osx to determine the encoding of the source files. – M A Feb 16 '15 at 08:52
1

Manouti provided an answer for why Java was not ignoring comment. About all I can say to Java is: dumb idea. They broke the compile process with something not supposed to be compiled.

To fix the problem in this case, javac needs an encoding specified via java.encoding. The easiest way appears to be the following:

$ /usr/local/bin/ant -Djava.encoding=ISO-8859-1 release
Buildfile: …/android-permission-explorer/build.xml

-set-mode-check:

-set-release-mode:

-release-obfuscation-check:
     [echo] proguard.config is ${proguard.config}

-pre-build:

-check-env:
 [checkenv] Android SDK Tools Revision 24.0.2
 [checkenv] Installed at /opt/android-sdk-macosx

-setup:
     [echo] Project Name: Permission Explorer
  [gettype] Project Type: Application

-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2
     [echo] Resolving Build Target for Permission Explorer...
[gettarget] Project Target:   Android 2.2
[gettarget] API level:        8
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: …/android-permission-explorer/bin/rsObj
    [mkdir] Created dir: …/android-permission-explorer/bin/rsLibs
     [echo] ----------
     [echo] Resolving Dependencies for Permission Explorer...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
     [echo] ----------
     [echo] Building Libraries with 'release'...
   [subant] No sub-builds to iterate on   

...
-dex:
      [dex] input: …/android-permission-explorer/bin/classes
      [dex] input: /opt/android-sdk-macosx/tools/support/annotations.jar
      [dex] Pre-Dexing /opt/android-sdk-macosx/tools/support/annotations.jar -> annotations-b850151b30962160fb610e078fc74448.jar
      [dex] Converting compiled files and external libraries into …/android-permission-explorer/bin/classes.dex...
       [dx] Merged dex A (37 defs/57.7KiB) with dex B (2 defs/1.1KiB). Result is 39 defs/66.6KiB. Took 0.1s

...
release:

BUILD SUCCESSFUL
Total time: 4 seconds

Another solution that worked is modifying the project's build.xml file with the following.

<project>
  ...
  <property name="java.encoding" value="ISO-8859-1" />
</project>
jww
  • 97,681
  • 90
  • 411
  • 885
  • Strictly speaking, the compiler itself still ignores comments. The problem is with the parser which parses the source file before passing it to the compilation task. You could look at it as a parsing problem and not as a compiler problem. – M A Feb 17 '15 at 22:22