【问题标题】:getting error while try to generate signed APK android studio 3尝试生成签名的 APK android studio 3 时出错
【发布时间】:2017-10-30 15:04:03
【问题描述】:

尝试在 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}

有人可以帮忙吗?

【问题讨论】:

  • 确保您的代码没有来自不受支持的 java 或 android 代码的类或函数。
  • 我怎么知道,该错误没有显示任何有关导致问题的文件的提示
  • This 回答可能会帮助您解决这个问题。
  • @AbhishekV 是的,我恢复到 gradle 2.3.3 而不是 gradle 3.0.0
  • @TheCrafter 是的,我恢复到 gradle 2.3.3 而不是 gradle 3.0.0

标签: android android-studio android-gradle-plugin


【解决方案1】:

XPP 答案对我不起作用。大多数交叉引用的答案都忽略了这可能是由其他库依赖项(即 JAR/AAR)引起的。在我的情况下,这个错误只出现在签名的构建过程中——未签名的构建很好。

运行 'gradlew :[MY-PROJECT]:dependencies' 会显示完整的依赖关系树。如果你发现一个依赖使用了 javax/java 命名空间中的 JAR 或类,那么你可以在你的依赖声明中添加一个 gradle exclude 语句,例如(gradle 4.1+):

api('my.favorite.dependency') { exclude group: 'javax' }

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

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

【讨论】:

    【解决方案2】:

    我看到了同样的错误。就我而言,发生这种情况是因为我包含了 logback。添加以下内容为我解决了这个问题(如here 所述):

    compile('com.github.tony19:logback-android-classic:1.1.1-6') {
        exclude group: 'com.google.android', module: 'android'
    }
    

    添加上述内容后,我仍然看到一个问题(如 here 所述),我必须添加以下内容:

    configurations {
        all {
            exclude module: 'httpclient'
        }
    }
    

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题。我遵循@Amira Elsayed Ismail 的建议并降级到 gradle 2.3.3

      构建错误消失了,但我收到了新的有线警告Warning:Ignoring Android API artifact com.google.android:android:4.1.1.4 for release。经过长时间的搜索,我知道出现此错误是因为我的项目依赖项之一依赖于 com.google.android:android,这意味着此依赖项已直接声明了对某个 Android 版本的依赖项。

      我必须知道我的哪个依赖项是导致该警告的原因。我尝试在 app\build.gradle 中一一注释依赖项并构建项目。

      就我而言,当我删除这个包compile 'com.sematext.android:sematext-logsene:1.0.0' 时,项目构建没有任何错误。

      现在我们找到了依赖于 android 版本的包,我们必须排除该内部依赖于 android 版本。

      我把compile 'com.sematext.android:sematext-logsene:1.0.0'改成了

      compile ('com.sematext.android:sematext-logsene:1.0.0'){
          exclude group: 'com.google.android'
      }
      

      现在一切正常;但我仍在使用 OLD gradle 版本。 我回到 app\build.gradle 并将 gradle 版本恢复到 3.0.1

      现在我解决了这个问题,仍然使用最新的 gradle。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-10
        • 2018-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-12
        • 2019-01-03
        • 1970-01-01
        相关资源
        最近更新 更多