Browse Source

实现安卓ota升级基础建设

master
王子贤 3 months ago
parent
commit
1c8acdaf02
6 changed files with 58 additions and 0 deletions
  1. 10
      android/app/build.gradle.kts
  2. 17
      android/app/src/main/AndroidManifest.xml
  3. 3
      android/app/src/main/res/xml/network_security_config.xml
  4. 4
      android/app/src/main/res/xml/ota_update_file_paths.xml
  5. 23
      lib/main.dart
  6. 1
      pubspec.yaml

10
android/app/build.gradle.kts

@ -13,6 +13,7 @@ android {
ndkVersion = "27.0.12077973" ndkVersion = "27.0.12077973"
compileOptions { compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
} }
@ -22,6 +23,7 @@ android {
} }
defaultConfig { defaultConfig {
multiDexEnabled = true
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.juxinghe.touchme" applicationId = "com.juxinghe.touchme"
// You can update the following values to match your application needs. // You can update the following values to match your application needs.
@ -104,3 +106,11 @@ android {
flutter { flutter {
source = "../.." source = "../.."
} }
dependencies {
// 注意:KTS 写法是 coreLibraryDesugaring(...)
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
// 如果你 minSdk <= 20 并开启了 multiDexEnabled,还需要:
// implementation("androidx.multidex:multidex:2.0.1")
}

17
android/app/src/main/AndroidManifest.xml

@ -14,6 +14,8 @@
<!-- 位置权限 --> <!-- 位置权限 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<application <application
android:label="趣恋恋" android:label="趣恋恋"
android:name="${applicationName}" android:name="${applicationName}"
@ -46,6 +48,21 @@
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
<provider
android:name="sk.fourq.otaupdate.OtaUpdateFileProvider"
android:authorities="${applicationId}.ota_update_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/ota_update_file_paths" />
</provider>
<receiver android:name="sk.fourq.otaupdate.InstallResultReceiver" android:exported="false">
<intent-filter>
<action android:name="${applicationId}.ACTION_INSTALL_COMPLETE"/>
</intent-filter>
</receiver>
</application> </application>
<!-- Required to query activities that can process text, see: <!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and https://developer.android.com/training/package-visibility and

3
android/app/src/main/res/xml/network_security_config.xml

@ -10,4 +10,7 @@
<min-tls-version>TLSv1.2</min-tls-version> <min-tls-version>TLSv1.2</min-tls-version>
</tls-config> </tls-config>
</base-config> </base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">oss.famitech.cn</domain>
</domain-config>
</network-security-config> </network-security-config>

4
android/app/src/main/res/xml/ota_update_file_paths.xml

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="internal_apk_storage" path="ota_update/"/>
</paths>

23
lib/main.dart

@ -20,6 +20,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import 'package:ota_update/ota_update.dart';
import 'extension/my_cupertino_localizations.dart'; import 'extension/my_cupertino_localizations.dart';
@ -168,6 +169,28 @@ class _MyAppState extends State<MyApp> {
_initIMAsync(); _initIMAsync();
// //
_checkAgreement(); _checkAgreement();
updateTest();
}
updateTest() async {
// try {
// OtaUpdate()
// .execute(
// 'http://oss.famitech.cn/ai_girlfriend/app/yuanyujiaowu_doubao.apk',
// // OPTIONAL
// destinationFilename: 'yuanyujiaowu_doubao.apk',
//
// ).listen(
// (OtaEvent event) {
// print(event.value);
// print("event.value");
// print(event.status);
// },
// );
// } catch (e) {
// print('Failed to make OTA update. Details: $e');
// }
} }
/// ///

1
pubspec.yaml

@ -78,6 +78,7 @@ dependencies:
pinput: ^6.0.1 pinput: ^6.0.1
im_flutter_sdk: 4.15.2 im_flutter_sdk: 4.15.2
webview_flutter: ^4.13.0 webview_flutter: ^4.13.0
ota_update: ^7.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save