Skip to content

Commit 728fc8d

Browse files
evil159jush
andauthored
Gradle 8 compatibility (#524)
* Add namespace attribute to plugin's build.gradle * Apply Gradle's plugins declaratively * Bump Gradle wrapper to version 8 for the example app * Add changelog entry * Bump Flutter sdk version on CI * Bump docker image for building Android on CI * Silence R8 errors * Update example/android/app/build.gradle Co-authored-by: Ramon <ramon.sadornilrivera@mapbox.com> * Remove proguard exclusions from the example app * Bump Kotlin to 1.8.22 in examples app --------- Co-authored-by: Ramon <ramon.sadornilrivera@mapbox.com>
1 parent 20cb112 commit 728fc8d

File tree

9 files changed

+55
-42
lines changed

9 files changed

+55
-42
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535
type: string
3636
default: example/build/app/outputs/apk
3737
docker:
38-
- image: cimg/android:2022.09
38+
- image: cimg/android:2024.04
3939
resource_class: 2xlarge
4040
steps:
4141
- checkout
4242
- flutter/install_sdk_and_pub:
43-
version: 3.16.9
43+
version: 3.19.6
4444
app-dir: example
4545
- run:
4646
name: ktlint
@@ -99,7 +99,7 @@ jobs:
9999
- add-mapbox-submodules-key
100100
- macos/install-rosetta
101101
- flutter/install_sdk_and_pub:
102-
version: 3.16.9
102+
version: 3.19.6
103103
app-dir: example
104104
- flutter/install_ios_pod:
105105
app-dir: example

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ PolylineAnnotationOptions(
162162
* Fix camera center not applied from map init options.
163163
* [iOS] Free up resources upon map widget disposal. This should help to reduce the amount of used memory when previously shown map widget is removed from the widget tree.
164164
* Fix multi-word enum cases decoding/encoding when being sent to/from the platform side.
165+
* [Android] Add Gradle 8 compatibility.
165166

166167
### 1.1.0
167168

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ apply plugin: 'kotlin-android'
4242
android {
4343
compileSdk 33
4444

45+
namespace 'com.mapbox.maps.mapbox_maps'
4546
sourceSets {
4647
main.java.srcDirs += 'src/main/kotlin'
4748
}
@@ -53,6 +54,10 @@ android {
5354
sourceCompatibility JavaVersion.VERSION_1_8
5455
targetCompatibility JavaVersion.VERSION_1_8
5556
}
57+
58+
kotlinOptions {
59+
jvmTarget = "1.8"
60+
}
5661
}
5762

5863
if (file("$rootDir/gradle/ktlint.gradle").exists() && file("$rootDir/gradle/lint.gradle").exists()) {

example/android/app/build.gradle

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
id "dev.flutter.flutter-gradle-plugin"
5+
}
6+
17
def localProperties = new Properties()
28
def localPropertiesFile = rootProject.file('local.properties')
39
if (localPropertiesFile.exists()) {
@@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
612
}
713
}
814

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1415
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1516
if (flutterVersionCode == null) {
1617
flutterVersionCode = '1'
@@ -21,21 +22,27 @@ if (flutterVersionName == null) {
2122
flutterVersionName = '1.0'
2223
}
2324

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2825
android {
29-
compileSdkVersion 34
26+
namespace "com.mapbox.maps.mapbox_maps_example"
27+
compileSdk 34
3028

3129
sourceSets {
3230
main.java.srcDirs += 'src/main/kotlin'
3331
}
3432

33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
kotlinOptions {
39+
jvmTarget = "1.8"
40+
}
41+
3542
defaultConfig {
3643
applicationId "com.mapbox.maps.flutter.example"
3744
minSdkVersion 21
38-
targetSdkVersion 31
45+
targetSdkVersion 33
3946
versionCode flutterVersionCode.toInteger()
4047
versionName flutterVersionName
4148
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -46,6 +53,8 @@ android {
4653
// TODO: Add your own signing config for the release build.
4754
// Signing with the debug keys for now, so `flutter run --release` works.
4855
signingConfig signingConfigs.debug
56+
minifyEnabled true
57+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
4958
}
5059
}
5160
}
@@ -55,7 +64,6 @@ flutter {
5564
}
5665

5766
dependencies {
58-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5967
androidTestImplementation 'androidx.test:runner:1.2.0'
6068
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
6169
}

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.mapbox.maps.mapbox_maps_example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- Flutter needs it to communicate with the running application
43
to allow setting breakpoints, to provide hot reload, etc.
54
-->

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.mapbox.maps.mapbox_maps_example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32

43
<!-- not needed? -->
54
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

example/android/build.gradle

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
buildscript {
2-
ext.kotlin_version = '1.7.10'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.4.2'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
}
12-
}
13-
141
allprojects {
152
repositories {
163
google()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Sep 04 18:43:58 EEST 2019
1+
#Tue Apr 30 20:27:36 EEST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

example/android/settings.gradle

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
511

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
18+
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.3.2" apply false
22+
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
23+
}
824

9-
def flutterSdkPath = properties.getProperty("flutter.sdk")
10-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11-
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
25+
include ":app"
1226

1327
if (file("../../../scripts/utils.gradle").exists()) {
1428
apply from: "../../../scripts/utils.gradle"

0 commit comments

Comments
 (0)