gpt4 book ai didi

android - 使用 Retrofit simplexml 转换器时出现编译错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:47:40 24 4
gpt4 key购买 nike

我是 android 和 xmpp 的初学者,我正在开发一个使用 xmpp 作为协议(protocol)并使用 openfire 作为服务器的聊天应用程序。我正在使用 xmpp rest api 创建一个组。要创建一个组,我需要向服务器发送 GET 请求带有 xml 数据主体。我在 android 客户端中使用 retrofit2。每当我构建我的应用程序时,它都会给我这个错误

错误:

E

rror: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: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 1

下面是我的改造代码

@GET("/plugins/restapi/v1/groups")
Call<Void> createGroup(@Header("Accept") String content_type,
@Header("Authorization") String authorization,
@Body Group group);

函数

public static int doCreateGroup(String content_type, String authorization, Group group) {
Retrofit retrofit = new Retrofit.Builder().baseUrl(StaticVariables.base_url)
.client(new OkHttpClient())
.addConverterFactory(SimpleXmlConverterFactory.create()).build();
Alfa alfa = retrofit.create(Alfa.class);
Call<Void> call = alfa.createGroup(content_type, authorization, group);
try {
Response<Void> response = call.execute();
Log.e("Group Upi", String.valueOf(response.code()));
return response.code();
} catch (IOException e) {
e.printStackTrace();
return 0;
}

}

下面是我的群模型

@Root(name = "group")
public class Group {
@Element(name = "name")
public String name;

@Element(name = "description")
public String description;

public Group(String name,String description){
this.description=description;
this.name=name;
}

}

下面是我必须发送的实际 xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<group>
<name>GroupName</name>
<description>Some description</description>
</group>

下面是我的依赖

compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'org.igniterealtime.smack:smack-android:4.1.4'
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
compile 'org.igniterealtime.smack:smack-im:4.1.4'
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-simplexml:2.1.0'
compile('com.digits.sdk.android:digits:1.10.3@aar') {
transitive = true;
}

请告诉我哪里错了

最佳答案

报错是因为simple xml converter中的一些类,所以我们只需要删除一些类,解决方法是,在gradle compile dependency中添加下面几行

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 - 使用 Retrofit simplexml 转换器时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39667972/

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