gpt4 book ai didi

java - 在 Android .aar 库中重新打包 .jar-s

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:12:44 28 4
gpt4 key购买 nike

源代码

Library

Project which uses Library

问题描述

我正在使用 .jar 库的那个库中编写 Android 库 (.aar)。

enter image description here

为了避免依赖重复,我使用ShadowJar插件重新打包,如下所示:

task shadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
System.out.println("Relocating packages...")
relocate 'retrofit' , 'com.codecraft.retrofit'
relocate 'org.simpleframework.xml', 'com.codecraft.org.simpleframework.xml'
relocate 'com.squareup.okhttp' , 'com.codecraft.com.squareup.okhttp'
}

在使用 Android 库 (.aar) 的应用程序中,我有如下所示的库的依赖项,只是为了测试我没有依赖项重复问题。

dependencies {
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-simplexml:2.0.0-beta1'
}

但是当我尝试在 Android 上运行应用程序时出现以下错误

enter image description here

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.bea.xml.stream.util.CircularQueue$1) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is not an inner class. Error:trouble processing "javax/xml/XMLConstants.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 :app:transformClassesWithDexForDebug FAILED Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

请注意如果我只添加改造依赖,这个问题不会出现在案例中

dependencies {
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
}

这是什么原因以及如何解决此错误?

最佳答案

当您在 lib 或应用程序中包含 Jars 时 - 您可能包含已经使用不同的 java 版本或使用与您的配置不同的配置编译的文件,这可能会导致与您遇到的问题类似的问题。

我猜你使用的依赖项是指一个库,它确实导致了 jar 创建的问题。

如果不使用依赖项对您来说至关重要 - 考虑下载您正在使用的库的代码(假设它们是开源的并且没有法律限制)并将它们与您的应用一起编译为项目中的附加模块,而不是添加 jar 。如果你这样做 - 你绝对应该考虑 jmols 写的关于库大小和方法计数的内容。

祝你好运!

关于java - 在 Android .aar 库中重新打包 .jar-s,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com