当我在尝试构建我的应用程序时收到“不明智或错误地使用核心类”错误时,我搜索了 Stackoverflow,并按照一些建议,使用 ant 和 jarjar 来构建应用程序。
ant 构建在 dx 步骤失败,错误报告如下。
我在网上搜索了有关如何修复“无法强制”错误的建议(见下文),但没有发现任何帮助。
请注意,ant 构建中的 jarjar 步骤似乎有效。当我检查 bin/repackagedclasses.jar 中的 java 目录的内容时,它们是空的,所有内容都转移到了等效的重命名目录 (/java)。
另请注意,我遵循的建议(使用 ant 和 jarjar)已有两年多的历史并适用于 android 2.x。有可能(可能?)使用 android 4 和相关基础设施,它们将无法工作,只是一个猜测。
最后一点。我在 sdk/platform-tools 中更改了 dx,如下所示:
exec java $javaOpts -jar "$jarpath" "$@"
exec java $javaOpts -jar "$jarpath" --core-library "$@"
无论是否进行上述更改,对 ant 构建或 Eclipse 构建都没有影响。
-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