匕首组件:错误:找不到符号kotlin类

时间:2019-07-09 15:21:35

标签: android kotlin dagger

生成的dagger组件即使没有读取行也找不到kotlin类的符号。

  

任务:app:compileStagingDebugJavaWithJavac失败

\app\build\generated\source\kapt\stagingDebug\...\DaggerAppComponent.java:49: error: cannot find symbol
import com...features.Main.splash_screen.SplashScreenActivity;
                                                                     ^
symbol:   class SplashScreenActivity
location: package com...features.Main.splash_screen

当我在Java中键入代码时,它将成功运行,并且此问题仅在Windows中发生。它不会出现在mac或linix中。

interface ISplashScreen  : IView {
    fun gotoMainScreen()
}

@Module
abstract class SplashModule {
    @Binds
    abstract fun provideISplash(splashScreenActivity: SplashScreenActivity): ISplashScreen
}


class SplashScreenActivity : BaseActivity<SplashScreenPresenter>(), ISplashScreen {

    @Inject
    lateinit var splashScreenPresenter: SplashScreenPresenter

    override fun gotoMainScreen() {
        Navigator.goToMainScreen(context)
    }

    override fun onCreateInit(savedInstanceState: Bundle?) {

    }

    override fun getLayout(): Int = R.layout.activity_splash

    override fun initPresenter(): SplashScreenPresenter = splashScreenPresenter
}

class SplashScreenPresenter @Inject constructor(view: ISplashScreen,
                                                environment: PresenterEnvironment)
    : BasePresenter<ISplashScreen>(view, environment) {

    // TODO : load project data by API
    @SuppressLint("CheckResult")
    override fun startLogic(savedInstance: Bundle?) {
        super.startLogic(savedInstance)
        Completable.timer(3, TimeUnit.SECONDS)
                .compose(getDestroyIoTransformer<Unit>())
                .subscribe {
                    view.gotoMainScreen()
                }
    }
}

@Module
public abstract class ActivityModule {

    @ContributesAndroidInjector(modules = SplashModule.class)
    abstract SplashScreenActivity bindSplashScreenActivity();

    @ContributesAndroidInjector(modules = { CartFragmentProvider.class, CategoryFragmentProvider.class})
    abstract MainActivity bindMainActivity();
}

//Gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'

implementation "com.google.dagger:dagger:2.23.1"
implementation "com.google.dagger:dagger-android-support:2.23.1"
kapt "com.google.dagger:dagger-compiler:2.23.1"
kapt "com.google.dagger:dagger-android-processor:2.23.1"

...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:49: error: cannot find symbol
import com....features.Main.splash_screen.SplashScreenActivity;
                                                                     ^
  symbol:   class SplashScreenActivity
  location: package com....features.Main.splash_screen
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:51: error: cannot find symbol
import com....features.Main.splash_screen.SplashScreenPresenter;
                                                                     ^
  symbol:   class SplashScreenPresenter
  location: package com....features.Main.splash_screen
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:3: error: cannot find symbol
import com....features.Main.splash_screen.SplashModule;
                                                                     ^
  symbol:   class SplashModule
  location: package com....features.Main.splash_screen
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:4: error: cannot find symbol
import com....features.Main.splash_screen.SplashScreenActivity;
                                                                     ^
  symbol:   class SplashScreenActivity
  location: package com....features.Main.splash_screen
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:25: error: cannot find symbol
  public interface SplashScreenActivitySubcomponent extends AndroidInjector<SplashScreenActivity> {
                                                                            ^
  symbol:   class SplashScreenActivity
  location: class ActivityModule_BindSplashScreenActivity
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:27: error: cannot find symbol
    interface Factory extends AndroidInjector.Factory<SplashScreenActivity> {}
                                                      ^
  symbol:   class SplashScreenActivity
  location: interface SplashScreenActivitySubcomponent
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:217: error: cannot find symbol
        SplashScreenActivity arg0) {
        ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentFactory
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:224: error: cannot find symbol
    private final SplashScreenActivity arg0;
                  ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:226: error: cannot find symbol
    private SplashScreenActivitySubcomponentImpl(SplashScreenActivity arg0Param) {
                                                 ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:233: error: cannot find symbol
    private SplashScreenPresenter getSplashScreenPresenter() {
            ^
  symbol:   class SplashScreenPresenter
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:237: error: cannot find symbol
    public void inject(SplashScreenActivity arg0) {
                       ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:240: error: cannot find symbol
    private SplashScreenActivity injectSplashScreenActivity(SplashScreenActivity instance) {
                                                            ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:240: error: cannot find symbol
    private SplashScreenActivity injectSplashScreenActivity(SplashScreenActivity instance) {
            ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:14: error: cannot find symbol
public final class SplashScreenActivity_MembersInjector implements MembersInjector<SplashScreenActivity> {
                                                                                   ^
  symbol: class SplashScreenActivity
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:25: error: cannot find symbol
  private final Provider<SplashScreenPresenter> splashScreenPresenterProvider;
                         ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:33: error: cannot find symbol
      Provider<SplashScreenPresenter> splashScreenPresenterProvider) {
               ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:48: error: cannot find symbol
      Provider<SplashScreenPresenter> splashScreenPresenterProvider) {
               ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:42: error: cannot find symbol
  public static MembersInjector<SplashScreenActivity> create(
                                ^
  symbol:   class SplashScreenActivity
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:52: error: cannot find symbol
  public void injectMembers(SplashScreenActivity instance) {
                            ^
  symbol:   class SplashScreenActivity
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:61: error: cannot find symbol
  public static void injectSplashScreenPresenter(SplashScreenActivity instance,
                                                 ^
  symbol:   class SplashScreenActivity
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenActivity_MembersInjector.java:62: error: cannot find symbol
      SplashScreenPresenter splashScreenPresenter) {
      ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenActivity_MembersInjector
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:8: error: cannot find symbol
public final class SplashScreenPresenter_Factory implements Factory<SplashScreenPresenter> {
                                                                    ^
  symbol: class SplashScreenPresenter
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:9: error: cannot find symbol
  private final Provider<ISplashScreen> viewProvider;
                         ^
  symbol:   class ISplashScreen
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:13: error: cannot find symbol
  public SplashScreenPresenter_Factory(Provider<ISplashScreen> viewProvider,
                                                ^
  symbol:   class ISplashScreen
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:20: error: cannot find symbol
  public SplashScreenPresenter get() {
         ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:24: error: cannot find symbol
  public static SplashScreenPresenter_Factory create(Provider<ISplashScreen> viewProvider,
                                                              ^
  symbol:   class ISplashScreen
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:29: error: cannot find symbol
  public static SplashScreenPresenter newInstance(ISplashScreen view,
                                                  ^
  symbol:   class ISplashScreen
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:29: error: cannot find symbol
  public static SplashScreenPresenter newInstance(ISplashScreen view,
                ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenPresenter_Factory
...\app\src\main\java\com\...\common\di\modules\ActivityModule.java:3: error: cannot find symbol
import com....features.Main.splash_screen.SplashModule;
                                                                     ^
  symbol:   class SplashModule
  location: package com....features.Main.splash_screen
...\app\src\main\java\com\...\common\di\modules\ActivityModule.java:4: error: cannot find symbol
import com....features.Main.splash_screen.SplashScreenActivity;
                                                                     ^
  symbol:   class SplashScreenActivity
  location: package com....features.Main.splash_screen
...\app\src\main\java\com\...\common\di\modules\ActivityModule.java:16: error: cannot find symbol
    abstract SplashScreenActivity bindSplashScreenActivity();
             ^
  symbol:   class SplashScreenActivity
  location: class ActivityModule
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:24: error: cannot find symbol
  @Subcomponent(modules = SplashModule.class)
                          ^
  symbol:   class SplashModule
  location: class ActivityModule_BindSplashScreenActivity
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\modules\ActivityModule_BindSplashScreenActivity.java:20: error: cannot find symbol
  @ClassKey(SplashScreenActivity.class)
            ^
  symbol:   class SplashScreenActivity
  location: class ActivityModule_BindSplashScreenActivity
...\app\src\main\java\com\...\common\di\modules\ActivityModule.java:15: error: cannot find symbol
    @ContributesAndroidInjector(modules = SplashModule.class)
                                          ^
  symbol:   class SplashModule
  location: class ActivityModule
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:143: error: cannot find symbol
    return MapBuilder.<Class<?>, Provider<AndroidInjector.Factory<?>>>newMapBuilder(2).put(SplashScreenActivity.class, (Provider) splashScreenActivitySubcomponentFactoryProvider).put(MainActivity.class, (Provider) mainActivitySubcomponentFactoryProvider).build();}
                                                                                           ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:234: error: cannot find symbol
      return new SplashScreenPresenter(arg0, DaggerAppComponent.this.providePresenterEnvironmentProvider.get());}
                 ^
  symbol:   class SplashScreenPresenter
  location: class DaggerAppComponent.SplashScreenActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\common\di\components\DaggerAppComponent.java:271: error: cannot find symbol
      return MapBuilder.<Class<?>, Provider<AndroidInjector.Factory<?>>>newMapBuilder(4).put(SplashScreenActivity.class, (Provider) DaggerAppComponent.this.splashScreenActivitySubcomponentFactoryProvider).put(MainActivity.class, (Provider) DaggerAppComponent.this.mainActivitySubcomponentFactoryProvider).put(CartFragment.class, (Provider) cartFragmentSubcomponentFactoryProvider).put(CategoriesFragment.class, (Provider) categoriesFragmentSubcomponentFactoryProvider).build();}
                                                                                             ^
  symbol:   class SplashScreenActivity
  location: class DaggerAppComponent.MainActivitySubcomponentImpl
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:21: error: cannot find symbol
    return new SplashScreenPresenter(viewProvider.get(), environmentProvider.get());
               ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenPresenter_Factory
...\app\build\generated\source\kapt\stagingDebug\com\...\features\Main\splash_screen\SplashScreenPresenter_Factory.java:31: error: cannot find symbol
    return new SplashScreenPresenter(view, environment);
               ^
  symbol:   class SplashScreenPresenter
  location: class SplashScreenPresenter_Factory
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
39 errors

FAILURE: Build failed with an exception.
  • 出了什么问题: 任务':app:compileStagingDebugJavaWithJavac'的执行失败。

      

    编译失败;有关详细信息,请参见编译器错误输出。

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。

  • https://help.gradle.org

  • 获得更多帮助

在此版本中使用了不推荐使用的Gradle功能,使其与Gradle 6.0不兼容。 使用“ --warning-mode all”来显示各个弃用警告。 参见https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

23秒内失败 50个可执行的任务:9个已执行,41个是最新的

2 个答案:

答案 0 :(得分:0)

只需将您的modules = SplashModule.class更改为modules = [SplashModule.class]

答案 1 :(得分:0)

您的项目使用 kapt 吗?

如果是这样,您可以禁用 kapt 的缓存。

在应用模块中打开您的 build.gradle 文件,并将 useBuildCache 设置为 false,并同步 Gradle。

尝试重建您的代码。

kapt {
    useBuildCache = false  
}

如果一切顺利,您可以再次启用 useBuildCache