新增编译模式下对日志进行输出,并且更新了hive缓存取出后进行连通性判断
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 构建 iOS (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 构建 iOS (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
Build Windows / build (push) Has been cancelled
(cherry picked from commit 40f95d0c463c31428c5f25118f59b0c3a60e73ba)
This commit is contained in:
@@ -84,7 +84,7 @@ class KRNetworkCheck {
|
||||
if (connectivityResult == ConnectivityResult.none) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 尝试进行实际的网络请求测试
|
||||
try {
|
||||
final result = await InternetAddress.lookup('www.apple.com');
|
||||
@@ -93,13 +93,51 @@ class KRNetworkCheck {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Android 平台保持原有逻辑
|
||||
final connectivityResult = await Connectivity().checkConnectivity();
|
||||
return connectivityResult != ConnectivityResult.none;
|
||||
// 🔧 Android 15 增强:多重验证网络可用性
|
||||
// 1. 检查连接状态(基础检查)
|
||||
final connectivityResult = await Connectivity().checkConnectivity().timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
debugPrint('⚠️ 连接性检查超时');
|
||||
return ConnectivityResult.none;
|
||||
},
|
||||
);
|
||||
|
||||
if (connectivityResult == ConnectivityResult.none) {
|
||||
debugPrint('❌ 网络未连接');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 🔧 Android 15 新增:尝试实际 DNS 解析验证网络可用性
|
||||
// 这在 Android 15 上很重要,因为系统可能报告网络已连接但实际无法访问
|
||||
try {
|
||||
final result = await InternetAddress.lookup('www.google.com').timeout(
|
||||
const Duration(seconds: 5),
|
||||
onTimeout: () {
|
||||
debugPrint('⚠️ DNS 解析超时,网络可能不稳定');
|
||||
return <InternetAddress>[];
|
||||
},
|
||||
);
|
||||
|
||||
if (result.isEmpty) {
|
||||
debugPrint('⚠️ DNS 解析失败,但允许继续(可能是网络延迟)');
|
||||
// 即使 DNS 解析失败,也允许继续,因为可能只是网络延迟
|
||||
return true;
|
||||
}
|
||||
|
||||
debugPrint('✅ 网络权限检查通过(连接性 + DNS 解析)');
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ DNS 解析异常: $e,但允许继续');
|
||||
// DNS 解析异常也允许继续,避免误判
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('网络权限检查错误: $e');
|
||||
return false;
|
||||
debugPrint('❌ 网络权限检查错误: $e');
|
||||
// 🔧 Android 15 优化:出错时返回 true,避免阻塞应用启动
|
||||
// 实际网络问题会在后续步骤中处理
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +150,7 @@ class KRNetworkCheck {
|
||||
if (connectivityResult == ConnectivityResult.none) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
final result = await InternetAddress.lookup('www.apple.com');
|
||||
return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
|
||||
@@ -120,12 +158,29 @@ class KRNetworkCheck {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
final connectivityResult = await Connectivity().checkConnectivity();
|
||||
return connectivityResult != ConnectivityResult.none;
|
||||
// 🔧 Android 15 增强:添加超时保护
|
||||
final connectivityResult = await Connectivity().checkConnectivity().timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
debugPrint('⚠️ 网络连接检查超时');
|
||||
return ConnectivityResult.none;
|
||||
},
|
||||
);
|
||||
|
||||
if (connectivityResult == ConnectivityResult.none) {
|
||||
debugPrint('❌ 网络未连接');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 🔧 Android 15 优化:对于已连接的网络,快速返回 true
|
||||
// 避免不必要的 DNS 查询延迟应用启动
|
||||
debugPrint('✅ 网络连接检查通过(${connectivityResult.name})');
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('网络连接检查错误: $e');
|
||||
return false;
|
||||
debugPrint('❌ 网络连接检查错误: $e');
|
||||
// 🔧 Android 15 优化:出错时返回 true,避免误判
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user