Android dx tool

后端 未结 3 1077
小鲜肉
小鲜肉 2020-12-14 01:55

Does anyone know of any documentation for dx?

In particular I am interested in knowing what the --core-library option does.

Can anybody shed a

3条回答
  •  遥遥无期
    2020-12-14 02:34

    the --core-library option on Dx will bypass the stupidity check that prevents you from accidentally including Java core libraries in you Android app.

    Dx will barf if you try to include a library that contains packages in the java.* or javax.* name space. the thinking is that classes in that name space are likely to depend on other JDK "core" classes, which will break your app since they (may) not be present on Android.

    now, of course, just because a java package starts with java.* or javax.* does not necessarily mean that it depends on the JDK proper. it may work perfectly fine in android. the recommendation, if you know what you are doing, if you know that your java/x.* classes don't depend on JDK core classes, is to use a tool like JarJar to repackage the JAR under a different name space.

    that being said, to get around the stupidity check, add the --core-library option to dx. change the last line of $ANDROID_HOME/platform-tools/dx from,

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

    to,

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

    in my case, i was including a library that depended on Jackson, which depends on JAXB. for me, overriding the stupidity check was acceptable because the library's use of Jackson was only for JSON and not for XML serialization (i only include the JAXB API library, not the impl). of course i wish there was a cleaner way to go about this, but re-writing the top level library to avoid using Jackson was not an option.

提交回复
热议问题