【Android】Hyperion-Android の導入メモ
概要
開発中のAndroid アプリをインストールした端末で色々な設定を確認するには、willowtreeapps/Hyperion-Android を導入すると手軽に出来ます。 あくまで開発用なので、くれぐれも本番アプリでは使わないようにお気をつけください。
使える機能
どのプラグインを導入するか次第ですが、下記のことがアプリ上で出来るようになります。
※GitHub リポジトリのREADME より引用
Core Plugins
- Hyperion-Attr - Inspect views and adjust their attributes.
- Hyperion-Build-Config - View application BuildConfig values.
- Hyperion-Crash - Show alternative activity when app crashes with the crash details. No UI for this module within drawer.
- Hyperion-Disk - Browse, delete, or share your app's files.
- Hyperion-Geiger-Counter - Check animation performance by listening for dropped frames. Please turn up the media volume. Haptic feedback is also supported. Inspired by KMCGeigerCounter.
- Hyperion-Measurement - Tap views to measure the distances between them.
- Hyperion-Phoenix - Clear local storage and relaunch the app.
- Hyperion-Recorder - Record, save, and share a video of your app.
- Hyperion-Shared-Preferences - View and edit your app's key-value storage.
- Hyperion-SQLite - Browse SQLite databases within your app.
- Hyperion-Timber - View Timber recorded log messages.
Third Party Plugins
- Hyperion-Chuck - Plugin which adds a button to inspect OkHttp traffic using Chuck
- Hyperion-AppInfo - Plugin which shows screen of details about an application
- Hyperion-Simple-Item - Plugin which adds simple menus
- Hyperion-DBFlow-Manager - Plugin which adds a button in inspect DBFlow databases and apply queries on it locally.
- Hyperion-kfin-state-machine - Plugin for checking the state of registered kfin-state-machine instances.
- Hyperion-Device-Info - View device market name and Android version.
- Hyperion-Font-Scale - Change system font scale.
ライセンス
Copyright (c) 2017 WillowTree, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
※GitHub リポジトリのLICENSE より引用
導入方法
アプリモジュールのbuild.gradle
に記述するだけで導入できます。
Core Plugin のSQLite 以外の機能が有効になります。
def ver_hyperion = "0.9.30"
debugImplementation "com.willowtreeapps.hyperion:hyperion-core:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-attr:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-build-config:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-crash:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-disk:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-geiger-counter:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-measurement:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-phoenix:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-recorder:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-shared-preferences:${ver_hyperion}"
debugImplementation "com.willowtreeapps.hyperion:hyperion-timber:${ver_hyperion}"
もし本番アプリ設定でもHyperion のコードを参照している場合は、 下記のように対応するno-op があるはずなので、そちらをrelease の依存関係に設定してください。
releaseImplementation "com.willowtreeapps.hyperion:hyperion-core-no-op:0.${ver_hyperion}"
使い方
Hyperion の設定をしたアプリをインストールするだけです。 アプリ起動後に端末を振るか、右側にHyperion のドロワーを引っ張って表示することでメニューが出てきます。
プラグインの自作方法
下記2つの手順できます。 debug フォルダー配下で実装することも可能でした。
1. 依存関係の追加
// def ver_hyperion = "0.9.30"
debugImplementation "com.willowtreeapps.hyperion:hyperion-plugin:0.9.${ver_hyperion}"
kapt "com.google.auto.service:auto-service:1.0-rc7"
2. コードの追加
2-1. 自作プラグインの実装
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import com.willowtreeapps.hyperion.plugin.v1.PluginModule
class HogePluginModule : PluginModule() {
override fun createPluginView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
val textView = TextView(parent.context)
textView.text = "Menu Title"
textView.textSize = 16f
textView.setOnClickListener {
Toast.makeText(
parent.context,
"Clicked!",
Toast.LENGTH_SHORT
).show()
}
return textView
}
}
2-2. 自作プラグインの登録
import com.google.auto.service.AutoService
import com.willowtreeapps.hyperion.plugin.v1.Plugin
import com.willowtreeapps.hyperion.plugin.v1.PluginModule
@AutoService(Plugin::class)
class HogePlugin : Plugin() {
override fun createPluginModule(): PluginModule? {
return HogePluginModule()
}
}
Tips
Activity を取得したい
PluginModule#createPluginView
内でextension.activity
とするとActivity が取得できます。
これを使うことでDialog を出したり、画面遷移したりすることが可能となります。
実装例はこんな感じです。
package work.shion.xapprecipe.hyperion
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.auto.service.AutoService
import com.willowtreeapps.hyperion.plugin.v1.Plugin
import com.willowtreeapps.hyperion.plugin.v1.PluginModule
import work.shion.xapprecipe.R
import work.shion.xapprecipe.templates.LaunchErrorDialog
@AutoService(Plugin::class)
class ShowLaunchErrorDialog : Plugin() {
override fun createPluginModule() = object : PluginModule() {
override fun createPluginView(
layoutInflater: LayoutInflater,
parent: ViewGroup
) = layoutInflater.inflate(R.layout.hyperion_menu, parent, false).apply {
findViewById<TextView>(R.id.hyperion_menu_title)?.setText(name)
setOnClickListener {
val activity = extension.activity
if (activity !is AppCompatActivity) {
return@setOnClickListener
}
LaunchErrorDialog.newInstance(
1000,
null
).show(activity.supportFragmentManager, LaunchErrorDialog.TAG)
}
}
override fun getName() = R.string.hyperion_show_launch_error_dialog_title
}
}
備考
- iOS アプリではHyperion-iOS があるので検討すると良いかもです。ただしAndroid 版に比べ機能は少ないです
- Stetho はChrome の開発者ツールで確認するので、こちらの方が手軽かもです
参考文献
- Hyperion-AndroidでAndroidアプリをデバッグしよう - Qiita (2019/12/26)
- willowtreeapps/Hyperion-Android (2020/12/02)