This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MediaBrowserCompat の connect() メソッドで Type checking has run into a recursive problem というエラーが出る場合、多くは コールバックの型推論が原因です。 | |
このエラーは、MediaBrowserConnectionCallback を匿名クラスとして connect() メソッドの引数に直接記述する際に、Kotlinコンパイラが型を正しく推論できずに再帰的なループに陥ってしまうことで発生します。 | |
解決策 | |
この問題を解決するには、以下の2つの方法が有効です。 | |
1. コールバックを変数として定義する | |
最も簡単で推奨される方法は、MediaBrowserConnectionCallback のインスタンスを一度変数に格納してから connect() メソッドに渡す方法です。これにより、コンパイラが型を明確に認識できるようになります。 | |
// 1. ConnectionCallbackを別の変数として定義する | |
val connectionCallback = object : MediaBrowserCompat.ConnectionCallback() { | |
override fun onConnected() { | |
// 接続が成功したときの処理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`MyQuery` のような Apollo Kotlin が生成するクエリクラスは、通常、プロジェクトの **`build` ディレクトリ内**に出力されます。 | |
### 基本的な出力先パス | |
生成されるファイルの一般的なパスのパターンは以下のようになります。 | |
``` | |
プロジェクトルート/モジュール名/build/generated/source/apollo/<sourceSetName>/<パッケージ名>/MyQuery.kt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum FileError: Error { | |
case fileNotFound | |
case dataReadError(Error) | |
} | |
func loadMp3DataFromBundle(fileName: String, fileExtension: String = "mp3") -> Result<Data, FileError> { | |
// 1. バンドルからファイルのURLを取得 | |
guard let fileURL = Bundle.main.url(forResource: fileName, withExtension: fileExtension) else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
もちろん、以下が **Kotlin Multiplatform (KMP) プロジェクトで `git submodule` を使って別の KMP プロジェクトを参照する方法** の Markdown 形式のまとめです。 | |
--- | |
# Kotlin Multiplatform プロジェクトで git submodule を使って他の KMP プロジェクトを参照する方法 | |
## 前提 | |
- **メインプロジェクト**: `MainKMPProject` | |
- **サブプロジェクト(参照元)**: `SubKMPProject`(Git リポジトリ管理されている) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GitHub Packages に Kotlin Multiplatform ライブラリを組織内限定で公開する方法(ステップバイステップ) | |
1. GitHub リポジトリを用意 | |
- Organization 内にリポジトリを作成 | |
- リポジトリは「Private」に設定(パッケージも限定公開になる) | |
2. build.gradle.kts に以下を追加 | |
publishing { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kotlin Multiplatform ライブラリをローカルで開発&使用する手順(Android Studio Meerkat対応) | |
Kotlin Multiplatform(KMP)でライブラリを作成し、ローカル環境で開発&別プロジェクトから利用する方法を解説します。 | |
この記事では、Android Studio Meerkat (2024.3.1 Patch 1) を使って、mavenLocal() にパブリッシュしたKMPライブラリを、 | |
他のプロジェクトから呼び出して使えるようにするまでをステップバイステップで紹介します。 | |
【ゴール】 | |
- Kotlin Multiplatformライブラリ(JVM対応)を作成 | |
- mavenLocal() に公開 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
import urllib.request, urllib.error | |
from bs4 import BeautifulSoup | |
# アクセスするURL | |
url = "http://www.nikkei.com/markets/kabu/" | |
# URLにアクセスする htmlが帰ってくる → <html><head><title>経済、株価、ビジネス、政治のニュース:日経電子版</title></head><body.... | |
html = urllib.request.urlopen(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
import urllib.request, urllib.error | |
from bs4 import BeautifulSoup | |
# アクセスするURL | |
url = "http://www.nikkei.com/" | |
# URLにアクセスする htmlが帰ってくる → <html><head><title>経済、株価、ビジネス、政治のニュース:日経電子版</title></head><body.... | |
html = urllib.request.urlopen(url) |