android - 尝试生成签名的 APK android studio 3 时出错

标签 android android-studio android-gradle-plugin

尝试在 android studio 3 中生成签名 APK 时出现以下错误

 Error:trouble processing "javax/xml/namespace/QName.class":
Error:Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:when not building a core library.
Error:This is often due to inadvertently including a core library file
Error:in your application's project, when using an IDE (such as
Error:Eclipse). If you are sure you're not intentionally defining a
Error:core class, then this is the most likely explanation of what's
Error:going on.
Error:However, you might actually be trying to define a class in a core
Error:namespace, the source of which you may have taken, for example,
Error:from a non-Android virtual machine project. This will most
Error:assuredly not work. At a minimum, it jeopardizes the
Error:compatibility of your app with future versions of the platform.
Error:It is also often of questionable legality.
Error:If you really intend to build a core library -- which is only
Error:appropriate as part of creating a full virtual machine
Error:distribution, as opposed to compiling an application -- then use
Error:the "--core-library" option to suppress this error message.
Error:If you go ahead and use "--core-library" but are in fact
Error:building an application, then be forewarned that your application
Error:will still fail to build or run, at some point. Please be
Error:prepared for angry customers who find, for example, that your
Error:application ceases to function once they upgrade their operating
Error:system. You will be to blame for this problem.
Error:If you are legitimately using some code that happens to be in a
Error:core package, then the easiest safe alternative you have is to
Error:repackage that code. That is, move the classes in question into
Error:your own package namespace. This means that they will never be in
Error:conflict with core system classes. JarJar is a tool that may help
Error:you in this endeavor. If you find that you cannot do this, then
Error:that is an indication that the path you are on will ultimately
Error:lead to pain, suffering, grief, and lamentation.
Error:1 error; aborting
Error:Execution failed for task ':_4SaleApp:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --multi-dex --main-dex-list /Volumes/Data/AMIRA/Work/Q84Sale/Q84Sale/_4SaleApp/build/intermediates/multi-dex/release/maindexlist.txt --output /Volumes/Data/AMIRA/Work/Q84Sale/Q84Sale/_4SaleApp/build/intermediates/transforms/dex/release/0 --min-sdk-version 16 /Volumes/Data/AMIRA/Work/Q84Sale/Q84Sale/_4SaleApp/build/intermediates/transforms/jarMerging/release/0.jar}

谁能帮忙吗?

最佳答案

XPP 答案对我不起作用。大多数交叉引用的答案都忽略了这可能是由其他库依赖项(即 JAR/AAR)引起的。在我的例子中,这个错误只出现在签名构建期间——未签名的构建没问题。

运行 'gradlew :[MY-PROJECT]:dependencies' 显示完整的依赖关系树。如果您在 javax/java 命名空间中找到使用 JAR 或类的依赖项,则可以将 gradle exclude 语句添加到您的依赖项声明中,例如 (gradle 4.1+):

api('my.favorite.dependency') { 排除组:'javax' }

然后再次运行 gradle ':dependencies' 任务。您应该看到排除的依赖项现在已从树中删除。如果此依赖项是编译所必需的,而其他地方未提供,则 build*/assemble* 任务将失败。如果在运行时需要依赖项并且没有在其他地方提供,例如。通过操作系统,然后是应用程序。将编译然后在运行时失败并出现“ClassNotFound”异常。

在最坏的情况下,如果依赖关系树没有多大帮助,那么您可能不得不开始注释掉依赖关系和使用它们的代码,以找到罪魁祸首的依赖关系。希望导致此错误的依赖项几乎没有被使用。一旦找到导致错误的依赖项,就需要使用两种方法之一来解决问题。用不会导致错误的东西替换 JAR/AAR;或重建依赖关系,以便 javax/java 类不与 JAR/AAR 一起导出。

关于android - 尝试生成签名的 APK android studio 3 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47018474/

相关文章:

java - 解析,带来所有结果

android - 创建android条码阅读器获取数据库信息

Java中的Android工作室gradle错误

androidTestCompile mockito 给出错误

java - 我正在尝试将 junit 与 apt 插件一起使用

android - 数据绑定(bind)失败, "couldn' 猜猜”

Android:在选项卡内传输字符串/值,每个选项卡都有自己的 Activity (Getters-Setter 除外)

Android NDK 增量构建

android-studio - Android Studio 不断运行旧代码

java - eclipse 中是否有生成资源的快捷方式(构造函数、get/set .....)