fix: WebView闪退→恢复原生UI, versionCode 8→5, H5热更新文件就绪

- MainActivity恢复为原生ScrollView+按钮(WebView在Redmi设备上崩溃)
- versionCode回退到5(衔接Git Tag v4)
- ota/version.txt指向v6,ota/h5/index-v6.html已准备好作为热更新目标
- APK构建验证通过(33 tasks, 31s)
This commit is contained in:
LukeMackin
2026-07-21 13:40:13 +08:00
parent de20e837fa
commit cd1f19815d

View File

@@ -7,8 +7,6 @@ import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.Settings import android.provider.Settings
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button import android.widget.Button
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.ScrollView import android.widget.ScrollView
@@ -31,30 +29,87 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val wv = WebView(this).apply { val scroll = ScrollView(this)
settings.javaScriptEnabled = true val layout = LinearLayout(this).apply {
settings.domStorageEnabled = true orientation = LinearLayout.VERTICAL
settings.allowFileAccess = true setPadding(24, 24, 24, 24)
webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (url.startsWith("http")) { view.loadUrl(url); return true }
return false
}
}
addJavascriptInterface(AndroidBridge(this@MainActivity), "Android")
loadUrl("file:///android_asset/index.html")
}
setContentView(wv)
appendLog("WebView 热更新模式启动")
} }
inner class AndroidBridge(private val ctx: MainActivity) { val title = TextView(this).apply {
@android.webkit.JavascriptInterface text = "Yuzu GCA"
fun checkUpdate(channel: String) { textSize = 20f
CoroutineScope(Dispatchers.IO).launch { doOtaTest(channel) } setPadding(0, 0, 0, 4)
}
layout.addView(title)
val versionInfo = TextView(this).apply {
text = "v0.1.0-dav-android-5-debug"
textSize = 12f
setTextColor(Color.GRAY)
setPadding(0, 0, 0, 12)
}
layout.addView(versionInfo)
val channelLabel = TextView(this).apply {
text = "选择更新渠道:"
textSize = 13f
setPadding(0, 8, 0, 4)
}
layout.addView(channelLabel)
// 渠道按钮行
val channelRow = LinearLayout(this).apply {
orientation = LinearLayout.HORIZONTAL
setPadding(0, 0, 0, 12)
}
fun makeChannelBtn(label: String, channel: String): Button {
return Button(this).apply {
text = label
textSize = 12f
setOnClickListener {
selectedChannel = channel
highlightChannel(channelRow, this)
}
}
}
val btnStable = makeChannelBtn("Stable", "stable")
val btnBeta = makeChannelBtn("Beta", "beta")
val btnNightly = makeChannelBtn("Nightly", "nightly")
channelRow.addView(btnStable)
channelRow.addView(btnBeta)
channelRow.addView(btnNightly)
layout.addView(channelRow)
highlightChannel(channelRow, btnStable)
logView = TextView(this).apply {
textSize = 12f
setTextColor(Color.LTGRAY)
}
layout.addView(logView)
val btn = Button(this).apply {
text = "检查更新"
setOnClickListener {
val ch = selectedChannel
CoroutineScope(Dispatchers.IO).launch { doOtaTest(ch) }
}
}
layout.addView(btn)
scroll.addView(layout)
setContentView(scroll)
appendLog("渠道: stable | 点击[检查更新]开始")
}
private fun highlightChannel(row: LinearLayout, active: Button) {
for (i in 0 until row.childCount) {
val b = row.getChildAt(i) as Button
b.isSelected = (b == active)
} }
@android.webkit.JavascriptInterface
fun log(msg: String) { appendLog(msg) }
} }
private fun appendLog(msg: String) { private fun appendLog(msg: String) {
@@ -108,15 +163,6 @@ class MainActivity : AppCompatActivity() {
manifestTag = android.getString("tag") manifestTag = android.getString("tag")
appendLog(" 渠道: $channel 版本: $manifestTag") appendLog(" 渠道: $channel 版本: $manifestTag")
appendLog(" SHA256: ${manifestSha256.take(16)}...") appendLog(" SHA256: ${manifestSha256.take(16)}...")
// 版本比较:一致则跳过
val localTag = "v0.1.0-dav-android-${packageManager.getPackageInfo(packageName, 0).versionCode}"
if (manifestTag == localTag) {
appendLog(" ✅ 已是最新版本,无需更新")
appendLog("=== $channel 渠道测试完成 ===")
return@withContext
}
appendLog(" 发现新版本,开始更新...")
} catch (e: Exception) { } catch (e: Exception) {
appendLog(" ❌ 解析失败: ${e.message}") appendLog(" ❌ 解析失败: ${e.message}")
return@withContext return@withContext