Skip to content

Commit 28f82c5

Browse files
committed
refactor(android): migrate to new Gradle plugin system
Updated Android project to use the new Gradle plugin DSL for better maintainability and compatibility. Also updated target SDK to 33, added android:exported attribute, and improved overall build configuration.
1 parent c08164d commit 28f82c5

File tree

5 files changed

+36
-49
lines changed

5 files changed

+36
-49
lines changed

example/android/app/build.gradle

Lines changed: 9 additions & 25 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,25 +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-
14-
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15-
if (flutterVersionCode == null) {
16-
flutterVersionCode = '1'
17-
}
18-
19-
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20-
if (flutterVersionName == null) {
21-
flutterVersionName = '1.0'
22-
}
23-
24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2815
android {
2916
compileSdkVersion 34
3017

@@ -45,9 +32,9 @@ android {
4532
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4633
applicationId "com.example.example"
4734
minSdkVersion flutter.minSdkVersion
48-
targetSdkVersion 30
49-
versionCode flutterVersionCode.toInteger()
50-
versionName flutterVersionName
35+
targetSdkVersion 33
36+
versionCode flutter.versionCode.toInteger()
37+
versionName flutter.versionName
5138
}
5239

5340
buildTypes {
@@ -63,6 +50,3 @@ flutter {
6350
source '../..'
6451
}
6552

66-
dependencies {
67-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
68-
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:theme="@style/LaunchTheme"
99
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1010
android:hardwareAccelerated="true"
11+
android:exported="true"
1112
android:windowSoftInputMode="adjustResize">
1213
<!-- Specifies an Android theme to apply to this Activity as soon as
1314
the Android process has started. This theme is visible to the user

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.9.20'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.7.0'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
}
12-
}
13-
141
allprojects {
152
repositories {
163
google()

example/android/settings.gradle

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
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+
}()
9+
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
211

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
518

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.7.0" apply false
22+
id "org.jetbrains.kotlin.android" version "1.9.20" 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'

openapi-generator/lib/src/gen_on_spec_changes.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ final _supportedRegexes = [jsonRegex, yamlRegex];
2727
/// It also throws an error when the specification doesn't exist on disk.
2828
///
2929
/// WARNING: THIS DOESN'T VALIDATE THE SPECIFICATION CONTENT
30-
FutureOr<Map<String, dynamic>> loadSpec({required InputSpec specConfig,
31-
bool isCached = false,
32-
http.Client? client}) async {
30+
FutureOr<Map<String, dynamic>> loadSpec(
31+
{required InputSpec specConfig,
32+
bool isCached = false,
33+
http.Client? client}) async {
3334
client ??= http.Client();
3435
print('loadSpec - ' + specConfig.path);
3536
// If the spec file doesn't match any of the currently supported spec formats

0 commit comments

Comments
 (0)