AbyssalBits — When My Emulator Ran An Old Build
I had fixed the bug in the code, but the emulator kept showing the broken version. The fresh build and install matched the current source. The build I was looking at was not the one I thought I was running.
View on Google PlayWhat happened when my emulator ran an old build
AbyssalBits is a pixel-art dark-fantasy action RPG and procedural dungeon crawler for Android. This is what happened when the emulator showed an old build.
The source was current and the game was old
After a round of cleanup, I launched the game on an Android emulator and it showed an old version label on the loading screen, along with older UI that I had already fixed. I opened the source and the newer implementation was right there. Nothing in the code explained what I was seeing.
Why it matters
When the running app disagrees with the source, the tempting move is to start debugging the code. That wastes time, because the code is not what you are looking at. Every test you do on a stale build tells you about an old version of the game.
What was done
So I treated it as a build and deploy problem first. I built a fresh debug APK from the checkout, installed it on the emulator, pulled the installed file back and compared checksums with the build output. They matched byte for byte, and the loading footer showed the current version label. The evidence points to stale local build and deploy state, not the code. What I could not do is name the exact cache or setting behind it.
For verification I also used Gradle's installDebug. In these test runs it did not use Android Studio's incremental delta deployment: it installed the whole APK through the package manager. A second run with 39 of 40 build tasks up to date still reinstalled the app. It was checked on an Android 16 emulator, the installed APK matched the fresh build, and the app launched with no crash. Android Studio has a matching setting, "Always install with package manager", and applying it in the IDE is left as an optional follow-up.
The lesson
Verify the build you are running before you debug the code. A checksum comparison between the installed APK and the one you just built takes a minute and tells you whether what you test is what you built. If something looks old, verify the installed build against the APK you just built before you touch the source.
Chuyện gì đã xảy ra khi emulator chạy bản build cũ
AbyssalBits là game action RPG pixel art, bối cảnh kỳ ảo đen tối, chơi theo kiểu leo hầm ngục ngẫu nhiên trên Android. Đây là chuyện đã xảy ra khi emulator hiện một bản build cũ.
Mã nguồn đã mới, còn game thì cũ
Sau một đợt dọn dẹp, mình chạy game trên emulator Android và thấy màn hình tải hiện nhãn phiên bản cũ, cùng giao diện cũ mà mình đã sửa rồi. Mình mở mã nguồn ra và phần triển khai mới nằm ngay đó. Không có gì trong code giải thích được điều mình đang nhìn thấy.
Vì sao chuyện này quan trọng
Khi ứng dụng đang chạy không khớp với mã nguồn, phản xạ dễ gặp là bắt tay vào gỡ lỗi code. Làm vậy mất thời gian, vì code không phải thứ bạn đang nhìn. Mọi thử nghiệm trên một bản build cũ chỉ cho bạn biết về một phiên bản cũ của game.
Đã làm gì
Vì vậy mình xem đây trước hết là vấn đề build và triển khai. Mình build một APK debug mới từ thư mục làm việc, cài lên emulator, kéo file đã cài về và so checksum với kết quả build. Hai file khớp từng byte, và phần chân màn hình tải hiện đúng nhãn phiên bản hiện tại. Bằng chứng cho thấy đó là trạng thái build và triển khai cũ trên máy, không phải do code. Điều mình không làm được là chỉ ra chính xác bộ nhớ đệm hay thiết lập nào gây ra.
Để kiểm chứng, mình cũng dùng installDebug của Gradle. Trong các lần chạy thử này, nó không dùng cơ chế triển khai gia tăng (delta) của Android Studio: nó cài toàn bộ APK qua package manager. Một lần chạy thứ hai, khi 39 trên 40 tác vụ build đã cập nhật sẵn, vẫn cài lại ứng dụng. Mình kiểm tra trên emulator Android 16: APK đã cài khớp với bản build mới và ứng dụng khởi chạy không bị crash. Android Studio có một thiết lập tương ứng là "Always install with package manager", và việc áp dụng nó trong IDE được để lại như một việc tùy chọn làm sau.
Bài học
Hãy kiểm tra bản build bạn đang chạy trước khi gỡ lỗi code. So checksum giữa APK đã cài và APK vừa build chỉ mất một phút và cho biết thứ bạn đang thử có đúng là thứ bạn đã build hay không. Nếu có gì trông cũ, hãy kiểm tra bản build đã cài so với APK bạn vừa build trước khi đụng vào mã nguồn.
エミュレーターが古いビルドを動かしていたときの話
AbyssalBits は Android 向けの、ダンジョンを探索するピクセルアートのダークファンタジー・アクション RPG です。エミュレーターに古いビルドが表示されたときに起きたことをまとめます。
ソースは最新なのに、ゲームは古かった
整理作業のあと、Android エミュレーターでゲームを起動すると、ローディング画面に古いバージョン表記が出て、すでに直したはずの古い UI も表示されました。ソースを開くと、新しい実装はちゃんとそこにありました。目の前の挙動を説明できるものは、コードの中にありませんでした。
なぜ重要か
動いているアプリがソースと食い違うと、すぐコードのデバッグを始めたくなります。しかし見ているのはコードではないので、時間の無駄です。古いビルドでしたテストは、すべてゲームの古いバージョンについて教えてくれるだけです。
やったこと
そこで、まずビルドとデプロイの問題として扱いました。チェックアウトから新しいデバッグ APK をビルドしてエミュレーターにインストールし、インストールされたファイルを取り出して、ビルド出力とチェックサムを比べました。バイト単位で一致し、ローディング画面のフッターには現在のバージョン表記が表示されていました。証拠からは、コードではなく、ローカルの古いビルドとデプロイの状態だったと考えられます。原因の具体的なキャッシュや設定までは特定できていません。
検証のために Gradle の installDebug も使いました。今回のテスト実行では、Android Studio の差分デプロイは使われず、APK 全体がパッケージマネージャー経由でインストールされました。ビルドタスク 40 件のうち 39 件が最新の状態だった 2 回目の実行でも、アプリは再インストールされました。Android 16 のエミュレーターで確認し、インストールされた APK は新しいビルドと一致し、アプリはクラッシュせずに起動しました。Android Studio にも同じ働きの設定「Always install with package manager」があり、IDE でのその適用は任意の後続作業として残しています。
この教訓
コードをデバッグする前に、動かしているビルドを確かめましょう。インストールされた APK と今ビルドした APK のチェックサム比較は 1 分で済み、テストしているものがビルドしたものかどうかが分かります。古く見えるなら、ソースに手を付ける前に、インストールされたビルドを今ビルドした APK と照合しましょう。

Comments
Post a Comment