【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


【Android】AGP を 8.3+ にすると AD_SERVICES_CONFIG プロパティが衝突する

バージョンアップ作業。

はい、またエラー出ました。


Error:
	Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:21.5.1] AndroidManifest.xml:32:13-58
	is also present at [com.google.android.gms:play-services-ads-lite:22.6.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config).
	Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.

Google Issue Tracker で以下。

From the Android Studio team:
This is a known issue of the AdMob and Google Services libraries
(AGP before 8.3 would have not surfaced the conflicts between the property definitions, which is why you see this during upgrade of AGP)

The solution suggested from the error message is the right one
Until the libraries are fixed: just override the property yourself in your AndroidManifest.xml

Android Studio チームからのコメント:
これは AdMob および Google Services ライブラリに関する既知の問題です。
(AGP 8.3 より前のバージョンでは、プロパティの定義間の競合が表面化しなかったため、AGP をアップグレードした際にこの問題が発生します)

エラーメッセージで提案されている解決策が正しい方法です。
ライブラリが修正されるまでの間は、AndroidManifest.xml 内でプロパティを自分で上書きしてください。


<property
    android:name="android.adservices.AD_SERVICES_CONFIG"
    android:resource="@xml/gma_ad_services_config"
    tools:replace="android:resource" />

DESCRIBE THE ISSUE IN DETAIL: I am not sure where can I report this issue as it seems it is more related to AdMob and Google Services manifest conflict. However this issue appears after updating to Iguana and AGP from 8.2.2 to 8.3 and Gradle 8.2 to 8.4.

この問題の報告先が分からず困っています。問題の原因は、AdMob と Google Services の AndroidManifest.xml における競合に関連しているように見えます。しかし、この問題は Iguana にアップデートし、Android Gradle Plugin (AGP) を 8.2.2 から 8.3 に、また Gradle を 8.2 から 8.4 に更新した後に発生するようになりました。

Status は Assigned のままで、まだ最近でも出ている模様。

[email protected] #50Nov 20, 2024 05:40PM
I upgraded from com.google.android.gms:play-services-ads:22.3.0' to com.google.android.gms:play-services-ads:23.5.0 and this error came.

<application> タグ内に書けばいいのか。

👉 Merge conflict with AndroidManifest in Android Studio Iguana [327696048] - Issue Tracker


SwiftUI・UIKit・AppKitでの画像処理の煩わしさを解消するためのヒント

図を作ってみました。

Appleの異なる画像処理フレームワーク(SwiftUI、UIKit、AppKit)間で画像データをやり取りする際のフロー図を示しています。

この図が示しているように、iOS や macOS で画像を扱う場合、複数の異なるフレームワーク(SwiftUI、UIKit、AppKit)間での画像データのやり取りが必要となることがよくあります。

しかし、それぞれのフレームワークは異なる画像型(UIKit では UIImage、AppKit では NSImage など)を使っているため、これらを統一して操作するのは煩雑です。

処理の煩わしさは以下の点にあります:

 

🧑🏻‍💻 異なる画像型の存在

UIKit、AppKit、Core Graphics などの各フレームワークはそれぞれ独自の画像データ型(UIImageNSImageCGImage など)を使います。

異なる画像型を相互に変換する必要があり、そのための変換処理が増えてしまいます。

 

🧑🏻‍💻 変換処理の多さ

SwiftUI の Image コンポーネントに画像を渡すには、UIKit の UIImage や AppKit の NSImage などの形式に適切に変換する必要があります。

例えば、UIImage を SwiftUI に渡すために Image(uiImage:) を使う必要があり、AppKit の NSImage なら Image(nsImage:) を使います。このように、変換手順が異なり、統一感に欠けます。

 

🧑🏻‍💻 データ型の制約と互換性

画像データをファイル形式(例えば、PNG や JPEG)に変換したり、ネットワークで送信する場合、Data 型を使う必要があります。

そのため、 UIImage.pngData()NSBitmapImageRep.representation(using:properties:) のような変換処理を追加で行わなければなりません。

こうした一連の変換処理は単純な画像表示のために多くの余分なコードを必要とし、開発者にとって煩わしいと感じる要因です。

 

🧑🏻‍💻 フレームワーク間の相違点

UIKit は iOS 向け、AppKitは macOS 向けのフレームワークなので、同じアプリをクロスプラットフォームで開発する際に、これらのフレームワーク間の違いに対応しなければならず、異なる API や処理方法に習熟する必要があります。

総じて、このような画像の処理は、単純に画像を表示・変換・送信したいだけであっても多くの手順が必要となるため、効率的でないことが多いです。

これが処理の煩わしさにつながっています。

 

🧑🏻‍💻 SwiftUI

Image(uiImage:) または Image(nsImage:) を使って、それぞれ UIKit の UIImage または AppKit の NSImage を表示できます。

ImageRenderer(content:) を使って、 UIImage または NSImage を作成することが可能です。

 

🧑🏻‍💻 UIKit の UIImage

SwiftUI の Image や AppKit の NSImage との間で画像の相互変換が可能です。

UIImagepngData() でPNGフォーマットのデータに変換できますし、 UIImage(data:) でデータから画像を生成できます。

 

🧑🏻‍💻 AppKit の NSImage

AppKit では NSImage.cgImage() で Core Graphics の CGImage を取得でき、NSBitmapImageRep クラスを使って画像表現の変換が行われます。

NSBitmapImageRep を通じて、NSImage は、PNGなどの形式でエクスポート可能です。

 

🧑🏻‍💻 Core GraphicsのCGImage

UIKit の UIImage や AppKitの NSImage と互換性があり、それらを通じて画像を描画・変換する基盤を提供します。

 

🧑🏻‍💻 Foundation の Data

UIImageNSImage から変換したデータ(例:PNG)を保持するデータ型。

これにより、画像データをファイルとして保存したり、ネットワークを通じて送信したりできます。

 

🧑🏻‍💻 したかったこと

AsyncImage 内での画像データの比較です。



302 リダイレクト後の画像を確認しています。

 

🧑🏻‍💻 まとめ

SwiftUI、UIKit、AppKit での画像処理は、それぞれのフレームワークが異なる画像形式を扱っているため、煩雑に感じることが多いです。

しかし、正しい変換手法を使い、CGImage などを活用すれば互換性を確保できます。

さらに、最新の API を使いこなすことで、画像処理を効率的に行い、開発の手間を減らすことが可能です。

この記事で紹介したヒントを参考に、より快適な画像処理の開発を目指しましょう。