0

When I received the "Ill-advised or mistaken usage of a core class" error while attempting to build my application, I searched through Stackoverflow and, as some suggested, used ant and jarjar to build the application.

The ant build failed at the dx step with the error reported below.

I searched the web for suggestions on how to fix the "can't coerce" error (see below) and found nothing that helped.

Please note that the jarjar step in the ant build seemed to work. When I checked the content of the java directories in bin/repackagedclasses.jar, they were empty with all of their content transferred to the equivalent renamed directories (/java).

Please also note that the suggestions I followed (using ant and jarjar) were more than two years old and applied to android 2.x. It is possible (likely?) that with android 4 and related infrastructure they will not work, just a guess.

One last point. I changed dx in sdk/platform-tools as follows:

exec java $javaOpts -jar "$jarpath" "$@"
exec java $javaOpts -jar "$jarpath" --core-library "$@"

With or without the above change, made no difference to the ant build or the Eclipse build.

-dex:
      [dex] Converting compiled files and external libraries into /home/adonnini/workspace3/CommManagerN6/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] com.android.dx.util.ExceptionWithContext: can't coerce string{"android.permission.ACCESS_CACHE_FILESYSTEM"} to Lcommmanager/java/lang/String;
       [dx]     at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
       [dx]     at com.android.dx.dex.cf.CfTranslator.processFields(CfTranslator.java:176)
       [dx]     at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:133)
       [dx]     at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
       [dx]     at com.android.dx.command.dexer.Main.processClass(Main.java:483)
       [dx]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
       [dx]     at com.android.dx.command.dexer.Main.access$400(Main.java:67)
       [dx]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx]     at com.android.dx.command.Main.main(Main.java:91)
       [dx] Caused by: java.lang.UnsupportedOperationException: can't coerce string{"android.permission.ACCESS_CACHE_FILESYSTEM"} to Lcommmanager/java/lang/String;
       [dx]     at com.android.dx.dex.cf.CfTranslator.coerceConstant(CfTranslator.java:210)
       [dx]     at com.android.dx.dex.cf.CfTranslator.processFields(CfTranslator.java:160)
       [dx]     ... 14 more
       [dx] ...while processing ACCESS_CACHE_FILESYSTEM Lcommmanager/java/lang/String;
       [dx] ...while processing android/commmanager/Manifest$permission.class
       [dx] 
       [dx] 1 error; aborting

BUILD FAILED
/home/adonnini/workspace3/CommManagerN6/build.xml:964: The following error occurred while executing this line:
/home/adonnini/workspace3/CommManagerN6/build.xml:376: null returned: 1
Intrications
  • 16,782
  • 9
  • 50
  • 50

1 Answers1

0

You didn't say what arguments you passed to jarjar, but by the looks of it you may have told it to change all references to classes in java.lang to instead be in your package namespace. If that's what you did, it certainly won't work, and the error you're getting is just the tip of the iceberg.

Here's a rough translation of the error: Some piece of code is declared to take an instance of class commmanager.java.lang.String, but it is being passed an instance of java.lang.String (that is, the class that any normal string constant is an instance of). There is no inheritance relationship between these two classes, and therefore the code is invalid.

At a minimum, you probably want to make your jarjar invocation more specific about what class names it's mangling.

danfuzz
  • 4,253
  • 24
  • 34
  • Hello danfuzz, Sorry for not including my build.xml. The relevant jarjar parameter is – user1673603 Sep 16 '12 at 23:46
  • Hello danfuzz. Your guess was correct. I was trying to follow the suggestion in the error message "... the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace. This means that they will never be in conflict with core system classes. JarJar is a tool that may help you in this endeavor ...". As you saw, it didn't work. I am running an experiment where I need to have the java.lang class in my package. Any ideas? – user1673603 Sep 17 '12 at 01:09
  • Any ideas? Well, you know how that error message says "…ill advised…" I'm pretty sure you're in that territory. :) – danfuzz Sep 17 '12 at 21:06