在Android .aar库中重新打包.jar-s [英] Repackaging .jar-s in Android .aar library

查看:261
本文介绍了在Android .aar库中重新打包.jar-s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图书馆

使用库的项目

问题描述

我正在使用.jar库在该库中编写Android库(.aar).

Problem Description

I'm writing Android Library (.aar) in that Library I'm using .jar libraries.

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

In order to avoid dependency duplication I'm using ShadowJar plugin for repackaging, as shown below:

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)的应用程序中,我具有下面所示库的依赖项,只是为了测试我是否没有依赖项重复问题.

In the application which is using Android Library (.aar) I have dependency of shown below libraries, just for testing that I have no dependency duplication issues.

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

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

But when I try to run application on Android I got following error

错误:警告:忽略匿名内部的InnerClasses属性 类错误:(com.bea.xml.stream.util.CircularQueue $ 1)不会 带有Error:associated EnclosingMethod属性.这个班 可能是由Error:compiler产生的,未针对 现代.class文件格式.推荐的错误:解决方案是 使用最新的编译器从源重新编译该类 错误:并且未指定任何"-target"类型选项.这 错误的后果:此警告是反映性的 此类的操作将错误地错误:表明它是 不是内部类.错误:无法处理"javax/xml/XMLConstants.class":错误:不建议使用或错误使用 核心类(java.*或javax.*)错误:未构建核心时 图书馆.错误:这通常是由于不小心包含了核心 库文件错误:在使用IDE时,在您的应用程序项目中 (例如Error:Eclipse).如果您确定自己不是故意的 定义一个Error:core类,那么这是最可能的解释 错误原因:继续.错误:但是,您实际上可能正在尝试 在核心Error:namespace中定义一个类,您可以从中获取源代码 例如,可能是从非Android虚拟机获取错误: 项目.这将是大多数错误:肯定无法正常工作.至少,它 危害错误:您的应用与未来版本的兼容性 平台.错误:它通常也具有可疑的合法性. 错误:如果您真的打算构建一个核心库-仅 错误:适合作为创建完整虚拟机的一部分 错误:分发,而不是编译应用程序-然后使用 错误:-core-library"选项禁止显示此错误消息. 错误:如果继续使用"--core-library",但实际上 错误:正在构建应用程序,然后警告您 应用程序错误:在某些时候仍将无法生成或运行. 请错误:为生气的顾客准备,例如,发现, 他们升级自己的错误:应用程序后,它们将停止运行 操作错误:系统.您将为此问题负责. 错误:如果您合法使用的代码恰好位于 错误:核心套件,那么最简单的安全替代方法是 错误:重新打包该代码.也就是说,将相关课程移至 错误:您自己的程序包名称空间.这意味着他们永远不会 错误:与核心系统类冲突. JarJar是一种可以 帮助错误:您正在努力.如果发现您无法执行此操作, 然后错误:这表明您所在的路径将 最终的错误:导致痛苦,痛苦,悲伤和悲哀. 错误:1个错误;正在中止:app:transformClassesWithDexForDebug失败 错误:任务执行失败 ':app:transformClassesWithDexForDebug'.

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

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

请注意,如果我仅添加改造依赖项,则不会出现此问题

PLEASE NOTE that this issue didn't appear in the case if I add only retrofit dependency

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

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

推荐答案

排除某些模块可以帮助我解决相同的错误:

Exclude of some modules helped me with same error:

compile ('com.squareup.retrofit2:converter-simplexml:2.1.0'){
    exclude group: 'xpp3', module: 'xpp3'
    exclude group: 'stax', module: 'stax-api'
    exclude group: 'stax', module: 'stax'
}

来源链接

这篇关于在Android .aar库中重新打包.jar-s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆