Skip to content

Commit 233c661

Browse files
authored
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]. <!-- Links --> [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
1 parent 4fa4313 commit 233c661

File tree

16 files changed

+336
-32
lines changed

16 files changed

+336
-32
lines changed

add_to_app/android_view/android_view/app/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ plugins {
44
}
55

66
android {
7-
compileSdkVersion 31
7+
compileSdk 34
8+
9+
lint {
10+
baseline = file("lint-baseline.xml")
11+
}
812

913
defaultConfig {
1014
applicationId "dev.flutter.example.androidView"
11-
minSdkVersion 16
12-
targetSdkVersion 30
15+
minSdkVersion 21
16+
targetSdkVersion 34
1317
versionCode 1
1418
versionName "1.0"
1519

@@ -32,11 +36,12 @@ android {
3236
buildFeatures {
3337
viewBinding true
3438
}
39+
namespace 'dev.flutter.example.androidView'
3540
}
3641

3742
dependencies {
3843
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
39-
implementation 'androidx.core:core-ktx:1.3.2'
44+
implementation 'androidx.core:core-ktx:1.10.0'
4045
implementation 'androidx.appcompat:appcompat:1.2.0'
4146
implementation 'com.google.android.material:material:1.2.1'
4247
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<issues format="6" by="lint 7.4.2" type="baseline" client="gradle" dependencies="false" name="AGP (7.4.2)" variant="all" version="7.4.2">
3+
4+
<issue
5+
id="RedundantLabel"
6+
message="Redundant label can be removed"
7+
errorLine1=" android:label=&quot;@string/app_name&quot;>"
8+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
9+
<location
10+
file="src/main/AndroidManifest.xml"
11+
line="14"
12+
column="13"/>
13+
</issue>
14+
15+
<issue
16+
id="GradleDependency"
17+
message="A newer version of org.jetbrains.kotlin:kotlin-stdlib than 1.8.22 is available: 1.9.20"
18+
errorLine1="}"
19+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
20+
<location
21+
file="build.gradle"
22+
line="39"
23+
column="20"/>
24+
</issue>
25+
26+
<issue
27+
id="GradleDependency"
28+
message="A newer version of androidx.core:core-ktx than 1.3.2 is available: 1.13.1"
29+
errorLine1=""
30+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
31+
<location
32+
file="build.gradle"
33+
line="40"
34+
column="20"/>
35+
</issue>
36+
37+
<issue
38+
id="GradleDependency"
39+
message="A newer version of androidx.appcompat:appcompat than 1.2.0 is available: 1.7.0"
40+
errorLine1="dependencies {"
41+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
42+
<location
43+
file="build.gradle"
44+
line="41"
45+
column="20"/>
46+
</issue>
47+
48+
<issue
49+
id="GradleDependency"
50+
message="A newer version of com.google.android.material:material than 1.2.1 is available: 1.12.0"
51+
errorLine1=" implementation &quot;org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version&quot;"
52+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
53+
<location
54+
file="build.gradle"
55+
line="42"
56+
column="20"/>
57+
</issue>
58+
59+
<issue
60+
id="GradleDependency"
61+
message="A newer version of androidx.constraintlayout:constraintlayout than 2.0.4 is available: 2.1.4"
62+
errorLine1=" implementation &apos;androidx.core:core-ktx:1.3.2&apos;"
63+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
64+
<location
65+
file="build.gradle"
66+
line="43"
67+
column="20"/>
68+
</issue>
69+
70+
<issue
71+
id="GradleDependency"
72+
message="A newer version of androidx.vectordrawable:vectordrawable than 1.1.0 is available: 1.2.0"
73+
errorLine1=" implementation &apos;androidx.appcompat:appcompat:1.2.0&apos;"
74+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
75+
<location
76+
file="build.gradle"
77+
line="44"
78+
column="20"/>
79+
</issue>
80+
81+
<issue
82+
id="GradleDependency"
83+
message="A newer version of androidx.lifecycle:lifecycle-livedata-ktx than 2.2.0 is available: 2.8.2"
84+
errorLine1=" implementation &apos;com.google.android.material:material:1.2.1&apos;"
85+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
86+
<location
87+
file="build.gradle"
88+
line="45"
89+
column="20"/>
90+
</issue>
91+
92+
<issue
93+
id="GradleDependency"
94+
message="A newer version of androidx.lifecycle:lifecycle-viewmodel-ktx than 2.2.0 is available: 2.8.2"
95+
errorLine1=" implementation &apos;androidx.constraintlayout:constraintlayout:2.0.4&apos;"
96+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
97+
<location
98+
file="build.gradle"
99+
line="46"
100+
column="20"/>
101+
</issue>
102+
103+
<issue
104+
id="GradleDependency"
105+
message="A newer version of androidx.navigation:navigation-fragment-ktx than 2.3.2 is available: 2.7.7"
106+
errorLine1=" implementation &apos;androidx.vectordrawable:vectordrawable:1.1.0&apos;"
107+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
108+
<location
109+
file="build.gradle"
110+
line="47"
111+
column="20"/>
112+
</issue>
113+
114+
<issue
115+
id="GradleDependency"
116+
message="A newer version of androidx.navigation:navigation-ui-ktx than 2.3.2 is available: 2.7.7"
117+
errorLine1=" implementation &apos;androidx.lifecycle:lifecycle-livedata-ktx:2.2.0&apos;"
118+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
119+
<location
120+
file="build.gradle"
121+
line="48"
122+
column="20"/>
123+
</issue>
124+
125+
<issue
126+
id="GradleDependency"
127+
message="A newer version of androidx.recyclerview:recyclerview than 1.1.0 is available: 1.3.2"
128+
errorLine1=" implementation &apos;androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0&apos;"
129+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
130+
<location
131+
file="build.gradle"
132+
line="49"
133+
column="20"/>
134+
</issue>
135+
136+
<issue
137+
id="GradleDependency"
138+
message="A newer version of androidx.test.ext:junit than 1.1.2 is available: 1.1.5"
139+
errorLine1=" implementation &quot;androidx.recyclerview:recyclerview:1.1.0&quot;"
140+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
141+
<location
142+
file="build.gradle"
143+
line="52"
144+
column="31"/>
145+
</issue>
146+
147+
<issue
148+
id="GradleDependency"
149+
message="A newer version of androidx.test.espresso:espresso-core than 3.3.0 is available: 3.5.1"
150+
errorLine1=" implementation project(path: &apos;:flutter&apos;)"
151+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
152+
<location
153+
file="build.gradle"
154+
line="53"
155+
column="31"/>
156+
</issue>
157+
158+
<issue
159+
id="GradleDynamicVersion"
160+
message="Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds (junit:junit:4.+)"
161+
errorLine1=" implementation &apos;androidx.navigation:navigation-ui-ktx:2.3.2&apos;"
162+
errorLine2=" ~~~~~~~~~~~~~~~~~">
163+
<location
164+
file="build.gradle"
165+
line="51"
166+
column="24"/>
167+
</issue>
168+
169+
<issue
170+
id="ExpiredTargetSdkVersion"
171+
message="Google Play requires that apps target API level 31 or higher.&#xA;"
172+
errorLine1=" defaultConfig {"
173+
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
174+
<location
175+
file="build.gradle"
176+
line="12"
177+
column="9"/>
178+
</issue>
179+
180+
<issue
181+
id="ObsoleteSdkInt"
182+
message="Unnecessary; SDK_INT is always >= 21"
183+
errorLine1=" &lt;item name=&quot;android:statusBarColor&quot; tools:targetApi=&quot;l&quot;>?attr/colorPrimaryVariant&lt;/item>"
184+
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
185+
<location
186+
file="src/main/res/values-night/themes.xml"
187+
line="13"
188+
column="45"/>
189+
</issue>
190+
191+
<issue
192+
id="ObsoleteSdkInt"
193+
message="Unnecessary; SDK_INT is always >= 21"
194+
errorLine1=" &lt;item name=&quot;android:statusBarColor&quot; tools:targetApi=&quot;l&quot;>?attr/colorPrimaryVariant&lt;/item>"
195+
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
196+
<location
197+
file="src/main/res/values/themes.xml"
198+
line="13"
199+
column="45"/>
200+
</issue>
201+
202+
<issue
203+
id="UnusedResources"
204+
message="The resource `R.dimen.activity_horizontal_margin` appears to be unused"
205+
errorLine1=" &lt;dimen name=&quot;activity_horizontal_margin&quot;>16dp&lt;/dimen>"
206+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
207+
<location
208+
file="src/main/res/values/dimens.xml"
209+
line="3"
210+
column="12"/>
211+
</issue>
212+
213+
<issue
214+
id="UnusedResources"
215+
message="The resource `R.dimen.activity_vertical_margin` appears to be unused"
216+
errorLine1=" &lt;dimen name=&quot;activity_vertical_margin&quot;>16dp&lt;/dimen>"
217+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
218+
<location
219+
file="src/main/res/values/dimens.xml"
220+
line="4"
221+
column="12"/>
222+
</issue>
223+
224+
<issue
225+
id="UnusedResources"
226+
message="The resource `R.drawable.ic_dashboard_black_24dp` appears to be unused"
227+
errorLine1="&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;"
228+
errorLine2="^">
229+
<location
230+
file="src/main/res/drawable/ic_dashboard_black_24dp.xml"
231+
line="1"
232+
column="1"/>
233+
</issue>
234+
235+
<issue
236+
id="UnusedResources"
237+
message="The resource `R.drawable.ic_home_black_24dp` appears to be unused"
238+
errorLine1="&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;"
239+
errorLine2="^">
240+
<location
241+
file="src/main/res/drawable/ic_home_black_24dp.xml"
242+
line="1"
243+
column="1"/>
244+
</issue>
245+
246+
<issue
247+
id="UnusedResources"
248+
message="The resource `R.drawable.ic_notifications_black_24dp` appears to be unused"
249+
errorLine1="&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;"
250+
errorLine2="^">
251+
<location
252+
file="src/main/res/drawable/ic_notifications_black_24dp.xml"
253+
line="1"
254+
column="1"/>
255+
</issue>
256+
257+
<issue
258+
id="MonochromeLauncherIcon"
259+
message="The application adaptive icon is missing a monochrome tag"
260+
errorLine1="&lt;adaptive-icon xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;>"
261+
errorLine2="^">
262+
<location
263+
file="src/main/res/mipmap-anydpi-v26/ic_launcher.xml"
264+
line="2"
265+
column="1"/>
266+
</issue>
267+
268+
<issue
269+
id="MonochromeLauncherIcon"
270+
message="The application adaptive roundIcon is missing a monochrome tag"
271+
errorLine1="&lt;adaptive-icon xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;>"
272+
errorLine2="^">
273+
<location
274+
file="src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml"
275+
line="2"
276+
column="1"/>
277+
</issue>
278+
279+
</issues>

add_to_app/android_view/android_view/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="dev.flutter.example.androidView">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<application
65
android:allowBackup="true"
@@ -11,6 +10,7 @@
1110
android:theme="@style/Theme.FlutterViewIntegration">
1211
<activity
1312
android:name=".MainActivity"
13+
android:exported="true"
1414
android:label="@string/app_name">
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />

add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/MainActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.Intent
88
import android.os.Bundle
99
import android.os.Parcelable
1010
import androidx.appcompat.app.AppCompatActivity
11+
import androidx.core.os.BundleCompat
1112
import androidx.recyclerview.widget.LinearLayoutManager
1213
import dev.flutter.example.androidView.databinding.ActivityMainBinding
1314
import io.flutter.FlutterInjector
@@ -61,7 +62,14 @@ class MainActivity : AppCompatActivity() {
6162
// If the activity was restarted, keep track of the previous scroll
6263
// position and of the previous cell indices that were randomly selected
6364
// as Flutter cells to preserve immersion.
64-
layoutManager.onRestoreInstanceState(savedInstanceState?.getParcelable<Parcelable>("layoutManager"))
65+
if (savedInstanceState != null) {
66+
val state = BundleCompat.getParcelable<Parcelable>(
67+
savedInstanceState,
68+
"layoutManager",
69+
Parcelable::class.java
70+
)
71+
layoutManager.onRestoreInstanceState(state)
72+
}
6573
val previousFlutterCellsArray = savedInstanceState?.getIntegerArrayList("adapter")
6674
if (previousFlutterCellsArray != null) {
6775
adapter.previousFlutterCells = TreeSet(previousFlutterCellsArray)

add_to_app/android_view/android_view/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.6.0"
3+
ext.kotlin_version = '1.8.0'
44
repositories {
55
google()
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.1.2'
9+
classpath 'com.android.tools.build:gradle:8.3.2'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111

1212
// NOTE: Do not place your application dependencies here; they belong

add_to_app/android_view/android_view/gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
1616
# https://developer.android.com/topic/libraries/support-library/androidx-rn
1717
android.useAndroidX=true
1818
# Kotlin code style for this project: "official" or "obsolete":
19-
kotlin.code.style=official
19+
kotlin.code.style=official
20+
android.nonTransitiveRClass=false
21+
android.nonFinalResIds=false
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Mar 10 09:46:16 PST 2021
21
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
42
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
64
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)