From 233c6613bb63a86cef2a0e546365608c48cb73c0 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Fri, 28 Jun 2024 11:47:08 -0400 Subject: [PATCH] Update add to app code to run on modern versions of agp and gradle. (#2330) ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md --- .../android_view/app/build.gradle | 13 +- .../android_view/app/lint-baseline.xml | 279 ++++++++++++++++++ .../app/src/main/AndroidManifest.xml | 4 +- .../example/androidView/MainActivity.kt | 10 +- .../android_view/android_view/build.gradle | 4 +- .../android_view/gradle.properties | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 5 +- .../flutter_module_using_plugin/lib/cell.dart | 4 +- .../flutter_module_using_plugin/pubspec.yaml | 4 +- .../android_using_plugin/app/build.gradle | 26 +- .../app/src/main/AndroidManifest.xml | 3 +- .../plugin/android_using_plugin/build.gradle | 2 +- .../android_using_plugin/gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../flutter_module_using_plugin/lib/cell.dart | 4 +- .../flutter_module_using_plugin/pubspec.yaml | 2 +- 16 files changed, 336 insertions(+), 32 deletions(-) create mode 100644 add_to_app/android_view/android_view/app/lint-baseline.xml diff --git a/add_to_app/android_view/android_view/app/build.gradle b/add_to_app/android_view/android_view/app/build.gradle index cf40f5d0c..7977fae89 100644 --- a/add_to_app/android_view/android_view/app/build.gradle +++ b/add_to_app/android_view/android_view/app/build.gradle @@ -4,12 +4,16 @@ plugins { } android { - compileSdkVersion 31 + compileSdk 34 + + lint { + baseline = file("lint-baseline.xml") + } defaultConfig { applicationId "dev.flutter.example.androidView" - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" @@ -32,11 +36,12 @@ android { buildFeatures { viewBinding true } + namespace 'dev.flutter.example.androidView' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.core:core-ktx:1.10.0' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' diff --git a/add_to_app/android_view/android_view/app/lint-baseline.xml b/add_to_app/android_view/android_view/app/lint-baseline.xml new file mode 100644 index 000000000..18092041f --- /dev/null +++ b/add_to_app/android_view/android_view/app/lint-baseline.xml @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/add_to_app/android_view/android_view/app/src/main/AndroidManifest.xml b/add_to_app/android_view/android_view/app/src/main/AndroidManifest.xml index 919153dcc..920589d73 100644 --- a/add_to_app/android_view/android_view/app/src/main/AndroidManifest.xml +++ b/add_to_app/android_view/android_view/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/MainActivity.kt b/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/MainActivity.kt index 9398eae56..5367a6056 100644 --- a/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/MainActivity.kt +++ b/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/MainActivity.kt @@ -8,6 +8,7 @@ import android.content.Intent import android.os.Bundle import android.os.Parcelable import androidx.appcompat.app.AppCompatActivity +import androidx.core.os.BundleCompat import androidx.recyclerview.widget.LinearLayoutManager import dev.flutter.example.androidView.databinding.ActivityMainBinding import io.flutter.FlutterInjector @@ -61,7 +62,14 @@ class MainActivity : AppCompatActivity() { // If the activity was restarted, keep track of the previous scroll // position and of the previous cell indices that were randomly selected // as Flutter cells to preserve immersion. - layoutManager.onRestoreInstanceState(savedInstanceState?.getParcelable("layoutManager")) + if (savedInstanceState != null) { + val state = BundleCompat.getParcelable( + savedInstanceState, + "layoutManager", + Parcelable::class.java + ) + layoutManager.onRestoreInstanceState(state) + } val previousFlutterCellsArray = savedInstanceState?.getIntegerArrayList("adapter") if (previousFlutterCellsArray != null) { adapter.previousFlutterCells = TreeSet(previousFlutterCellsArray) diff --git a/add_to_app/android_view/android_view/build.gradle b/add_to_app/android_view/android_view/build.gradle index 00b68e449..f6f55b661 100644 --- a/add_to_app/android_view/android_view/build.gradle +++ b/add_to_app/android_view/android_view/build.gradle @@ -1,12 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.6.0" + ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'com.android.tools.build:gradle:8.3.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/add_to_app/android_view/android_view/gradle.properties b/add_to_app/android_view/android_view/gradle.properties index 252175276..c8ce6fbcc 100644 --- a/add_to_app/android_view/android_view/gradle.properties +++ b/add_to_app/android_view/android_view/gradle.properties @@ -16,4 +16,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +android.nonTransitiveRClass=false +android.nonFinalResIds=false \ No newline at end of file diff --git a/add_to_app/android_view/android_view/gradle/wrapper/gradle-wrapper.properties b/add_to_app/android_view/android_view/gradle/wrapper/gradle-wrapper.properties index ee67d29dc..17655d0ef 100644 --- a/add_to_app/android_view/android_view/gradle/wrapper/gradle-wrapper.properties +++ b/add_to_app/android_view/android_view/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Mar 10 09:46:16 PST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/add_to_app/android_view/flutter_module_using_plugin/lib/cell.dart b/add_to_app/android_view/flutter_module_using_plugin/lib/cell.dart index 59e3c7b71..199199268 100644 --- a/add_to_app/android_view/flutter_module_using_plugin/lib/cell.dart +++ b/add_to_app/android_view/flutter_module_using_plugin/lib/cell.dart @@ -6,7 +6,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:sensors/sensors.dart'; +import 'package:sensors_plus/sensors_plus.dart'; // This is on alternate entrypoint for this module to display Flutter UI in // a (multi-)view integration scenario. @@ -109,7 +109,7 @@ class _CellState extends State with WidgetsBindingObserver { // Don't continuously rebuild for nothing when the // cell isn't visible. stream: appLifecycleState == AppLifecycleState.resumed - ? accelerometerEvents + ? accelerometerEventStream() : Stream.value(defaultPosition), initialData: defaultPosition, builder: (context, snapshot) { diff --git a/add_to_app/android_view/flutter_module_using_plugin/pubspec.yaml b/add_to_app/android_view/flutter_module_using_plugin/pubspec.yaml index 9953baaca..7ea5799bb 100644 --- a/add_to_app/android_view/flutter_module_using_plugin/pubspec.yaml +++ b/add_to_app/android_view/flutter_module_using_plugin/pubspec.yaml @@ -10,8 +10,8 @@ dependencies: flutter: sdk: flutter provider: ^6.0.2 - url_launcher: ^6.0.6 - sensors: ^2.0.3 + url_launcher: ^6.0.20 + sensors_plus: ^5.0.1 dev_dependencies: analysis_defaults: diff --git a/add_to_app/plugin/android_using_plugin/app/build.gradle b/add_to_app/plugin/android_using_plugin/app/build.gradle index 941b8bb4f..546c701bb 100644 --- a/add_to_app/plugin/android_using_plugin/app/build.gradle +++ b/add_to_app/plugin/android_using_plugin/app/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 33 + compileSdk 34 defaultConfig { applicationId "dev.flutter.example.androidusingplugin" - minSdkVersion 19 - targetSdkVersion 33 + minSdkVersion 21 + targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -17,19 +17,29 @@ android { minifyEnabled false } } + // Remove when #flutter/flutter/issues/150955 is merged to stable. + lintOptions { + checkReleaseBuilds false + } + // Keep java and kotlin versions in sync. compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } + kotlinOptions { + jvmTarget = '1.8' + } + + namespace 'dev.flutter.example.androidusingplugin' } dependencies { implementation project(':flutter') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'androidx.core:core-ktx:1.13.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/add_to_app/plugin/android_using_plugin/app/src/main/AndroidManifest.xml b/add_to_app/plugin/android_using_plugin/app/src/main/AndroidManifest.xml index 8766e128d..f0161e6a8 100644 --- a/add_to_app/plugin/android_using_plugin/app/src/main/AndroidManifest.xml +++ b/add_to_app/plugin/android_using_plugin/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + with WidgetsBindingObserver { // Don't continuously rebuild for nothing when the // cell isn't visible. stream: appLifecycleState == AppLifecycleState.resumed - ? accelerometerEvents + ? accelerometerEventStream() : Stream.value(defaultPosition), initialData: defaultPosition, builder: (context, snapshot) { diff --git a/add_to_app/plugin/flutter_module_using_plugin/pubspec.yaml b/add_to_app/plugin/flutter_module_using_plugin/pubspec.yaml index 201d1f218..7ea5799bb 100644 --- a/add_to_app/plugin/flutter_module_using_plugin/pubspec.yaml +++ b/add_to_app/plugin/flutter_module_using_plugin/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: sdk: flutter provider: ^6.0.2 url_launcher: ^6.0.20 - sensors: ^2.0.3 + sensors_plus: ^5.0.1 dev_dependencies: analysis_defaults: