【Android】Hilt + KSP で error.NonExistentClass を解決するヒント - Protobuf / SQLDelight / ViewBinding / AIDL

見かけましたよね。

以下に似たようなエラー。


e: [ksp] InjectProcessingStep was unable to process 'RemoteUnfoldTransitionReceiver(boolean,java.util.concurrent.Executor)' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.RemoteUnfoldTransitionReceiver
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: [ksp] InjectProcessingStep was unable to process 'UnfoldTransitionProgressForwarder()' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.UnfoldTransitionProgressForwarder
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: [ksp] ComponentProcessingStep was unable to process 'com.android.systemui.unfold.RemoteUnfoldSharedComponent' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.android.systemui.unfold.progress.RemoteUnfoldTransitionReceiver
    => type (ERROR superclass): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.
e: Error occurred in KSP, check log for detail

私は、SDKバージョンアップ時に SQLDelight で出会いましたが以下で回避。


// bottom of app/build.gradle.kts

androidComponents {
  onVariants(selector().all()) { variant ->
    afterEvaluate {
      val capName = variant.name.capitalize()
      tasks.getByName<KotlinCompile>("ksp${capName}Kotlin") {
        setSource(tasks.getByName("generate${capName}DatabaseInterface").outputs)
      }
    }
  }
}

👉 [ksp] InjectProcessingStep was unable to process a class which extends Binder Stub because 'error.NonExistentClass' could not be resolved. · Issue #4158 · google/dagger

こんな「とりあえず回避」ってのよくありますが

対応コードが溜まっていくと後々意味不明になるので

なんか嫌ですけど、

仕方ないんですよね。

👉 SqlDelight inconsistency with KSP · Issue #5473 · sqldelight/sqldelight
👉 KSP Compilation Failure: Unresolved `error.NonExistentClass` during `MarketDaoImpl` and `LocalDatasourceModule` processing · Issue #2092 · google/ksp
👉 SQLDelight 2.0 Tasks · Issue #2694 · sqldelight/sqldelight


関連ワード:  AndroiddaggerGoogleGradleKotlinSquareライブラリ開発