Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchFieldError: No field Companion of type #480

Closed
q947721485 opened this issue Jan 20, 2024 · 10 comments
Closed

java.lang.NoSuchFieldError: No field Companion of type #480

q947721485 opened this issue Jan 20, 2024 · 10 comments

Comments

@q947721485
Copy link

q947721485 commented Jan 20, 2024

java.lang.NoSuchFieldError: No field Companion of type Lrxhttp/wrapper/param/RxHttp$Companion; 
in class Lrxhttp/wrapper/param/RxHttp; 
or its superclasses (declaration of 'rxhttp.wrapper.param.RxHttp' appears in /data/app/~~WKe7naLd7ecjnJoA3eKrWQ==/com.xishidaojia.fuwu-XHrp4duSyPJkNugOeeDssA==/base.apk!classes10.dex)

环境 使用ksp编译 版本3.2.3 ksp版本 1.9.20-1.0.14 无多module依赖 在compose 目前不知道具体问题在什么地方

@liujingxing
Copy link
Owner

什么情况下出现此问题?打包后?把module结构,及RxHttp依赖配置截图发出

@liujingxing
Copy link
Owner

在Java还是kotlin环境中调用?依赖的kotlin版本又是多少

@q947721485
Copy link
Author

在kotlin 环境下调用的,kotlin版本为1.9.20 。在调试环境下,运行后调用rxhttp请求网络时出现的
WechatIMG1
WechatIMG2
WechatIMG3
WechatIMG4
WechatIMG5
WechatIMG6
WechatIMG7

@liujingxing
Copy link
Owner

把kotlin版本改为1.9.10,ksp改为1.9.10-1.0.13再试试,还是不行话,加我微信 ljx-studio

@q947721485
Copy link
Author

好的我先试一下再过来回复

@q947721485
Copy link
Author

你好,还是不行加你微信了

@liujingxing
Copy link
Owner

liujingxing commented Jan 21, 2024

问题已找到,原因是,rxhttp-compilerkapt注解处理器hilt有点冲突,即使使用ksp依赖rxhttp-compiler,hilt依然会调用rxhttp-compilerkapt注解处理器去生成Java版本的RxHttp类,而ksp依赖rxhttp-compiler,又会生成一份kotlin版本RxHttp`类,如下图所示:
image

导致在代码合并时,把kotlin版本的RxHttp类丢失了,而Java版本的RxHttp类,是没有RxHttp$Companion变量的,所以就报错了,下个版本会规避这个问题

@liujingxing
Copy link
Owner

在已使用ksp依赖rxhttp-compiler的情况下,复现步骤如下
1、在项目的build.gradle文件中添加一下代码

buildscript {

    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.48.1'
    }
}

plugins {
    id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false
}

2、在module的build.gradle文件中添加以下代码

plugins {
    id 'dagger.hilt.android.plugin'
}

dependencies {
    implementation "com.google.dagger:hilt-android:2.48.1"
    ksp "com.google.dagger:hilt-android-compiler:2.48.1"  //kapt或ksp一样有问题
}

3、使用hilt任一注解,如:

@HiltAndroidApp
public class AppHolder extends Application {
    //省略部分代码
}

项目同步成功后,rebuild一下项目,此时就会出现两个RxHttp类

@liujingxing
Copy link
Owner

注:使用kapt依赖rxhttp-compiler没有此问题

@liujingxing
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants