Skip to content

Commit d297bd3

Browse files
committed
android gradle migration
1 parent f677bb2 commit d297bd3

File tree

15 files changed

+90
-124
lines changed

15 files changed

+90
-124
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}

example/android/.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ gradle-wrapper.jar
77
GeneratedPluginRegistrant.java
88

99
# Remember to never publicly share your keystore.
10-
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
10+
# See https://flutter.dev/to/reference-keystore
1111
key.properties
12+
**/*.keystore
13+
**/*.jks

example/android/app/build.gradle

+22-45
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,45 @@
1-
def localProperties = new Properties()
2-
def localPropertiesFile = rootProject.file('local.properties')
3-
if (localPropertiesFile.exists()) {
4-
localPropertiesFile.withReader('UTF-8') { reader ->
5-
localProperties.load(reader)
6-
}
7-
}
8-
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.")
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id "dev.flutter.flutter-gradle-plugin"
126
}
137

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-
288
android {
29-
compileSdkVersion 34
9+
namespace = "dev.jeremyko.plugin_example_example"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
3012

31-
sourceSets {
32-
main.java.srcDirs += 'src/main/kotlin'
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_17
15+
targetCompatibility = JavaVersion.VERSION_17
16+
}
17+
18+
kotlinOptions {
19+
jvmTarget = '17'
3320
}
3421

3522
defaultConfig {
3623
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3724
applicationId "dev.jeremyko.proximity_sensor_example"
3825
namespace "dev.jeremyko.proximity_sensor_example"
26+
// You can update the following values to match your application needs.
27+
// For more information, see: https://flutter.dev/to/review-gradle-config.
3928
minSdkVersion 23
40-
targetSdkVersion 34
41-
versionCode flutterVersionCode.toInteger()
42-
versionName flutterVersionName
29+
targetSdk = flutter.targetSdkVersion
30+
versionCode = flutter.versionCode
31+
versionName = flutter.versionName
4332
}
4433

4534
buildTypes {
4635
release {
4736
// TODO: Add your own signing config for the release build.
4837
// Signing with the debug keys for now, so `flutter run --release` works.
49-
signingConfig signingConfigs.debug
38+
signingConfig = signingConfigs.debug
5039
}
5140
}
52-
53-
compileOptions {
54-
sourceCompatibility JavaVersion.VERSION_17
55-
targetCompatibility JavaVersion.VERSION_17
56-
}
57-
kotlinOptions {
58-
jvmTarget = '17'
59-
}
6041
}
6142

6243
flutter {
63-
source '../..'
64-
}
65-
66-
dependencies {
67-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
44+
source = "../.."
6845
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="dev.jeremyko.proximity_sensor_example">
3-
<!-- Flutter needs it to communicate with the running application
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->
66
<uses-permission android:name="android.permission.INTERNET"/>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2-
<uses-permission android:name="android.hardware.sensor.proximity"/>
3-
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/>
4-
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
5-
<uses-permission android:name="android.permission.WAKE_LOCK"/>
6-
<application
2+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
3+
<application
74
android:label="proximity_sensor_example"
5+
android:name="${applicationName}"
86
android:icon="@mipmap/ic_launcher">
97
<activity
10-
android:exported="true"
118
android:name=".MainActivity"
9+
android:exported="true"
1210
android:launchMode="singleTop"
11+
android:taskAffinity=""
1312
android:theme="@style/LaunchTheme"
1413
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1514
android:hardwareAccelerated="true"
@@ -22,15 +21,6 @@
2221
android:name="io.flutter.embedding.android.NormalTheme"
2322
android:resource="@style/NormalTheme"
2423
/>
25-
<!-- Displays an Android View that continues showing the launch screen
26-
Drawable until Flutter paints its first frame, then this splash
27-
screen fades out. A splash screen is useful to avoid any visual
28-
gap between the end of Android's launch screen and the painting of
29-
Flutter's first frame. -->
30-
<meta-data
31-
android:name="io.flutter.embedding.android.SplashScreenDrawable"
32-
android:resource="@drawable/launch_background"
33-
/>
3424
<intent-filter>
3525
<action android:name="android.intent.action.MAIN"/>
3626
<category android:name="android.intent.category.LAUNCHER"/>
@@ -42,4 +32,15 @@
4232
android:name="flutterEmbedding"
4333
android:value="2" />
4434
</application>
35+
<!-- Required to query activities that can process text, see:
36+
https://developer.android.com/training/package-visibility and
37+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
38+
39+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
40+
<queries>
41+
<intent>
42+
<action android:name="android.intent.action.PROCESS_TEXT"/>
43+
<data android:mimeType="text/plain"/>
44+
</intent>
45+
</queries>
4546
</manifest>

example/android/app/src/main/kotlin/dev/jeremyko/proximity_sensor_example/MainActivity.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package dev.jeremyko.proximity_sensor_example
22

33
import io.flutter.embedding.android.FlutterActivity
44

5-
class MainActivity: FlutterActivity() {
6-
}
5+
class MainActivity: FlutterActivity()

example/android/app/src/main/res/values-night/styles.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
44
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
55
<!-- Show a splash screen on the activity. Automatically removed when
6-
Flutter draws its first frame -->
6+
the Flutter engine draws its first frame -->
77
<item name="android:windowBackground">@drawable/launch_background</item>
88
</style>
99
<!-- Theme applied to the Android Window as soon as the process has started.
1010
This theme determines the color of the Android Window while your
1111
Flutter UI initializes, as well as behind your Flutter UI while its
1212
running.
13-
13+
1414
This Theme is only used starting with V2 of Flutter's Android embedding. -->
1515
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
1616
<item name="android:windowBackground">?android:colorBackground</item>

example/android/app/src/main/res/values/styles.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
44
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
55
<!-- Show a splash screen on the activity. Automatically removed when
6-
Flutter draws its first frame -->
6+
the Flutter engine draws its first frame -->
77
<item name="android:windowBackground">@drawable/launch_background</item>
88
</style>
99
<!-- Theme applied to the Android Window as soon as the process has started.
1010
This theme determines the color of the Android Window while your
1111
Flutter UI initializes, as well as behind your Flutter UI while its
1212
running.
13-
13+
1414
This Theme is only used starting with V2 of Flutter's Android embedding. -->
1515
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
1616
<item name="android:windowBackground">?android:colorBackground</item>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="dev.jeremyko.proximity_sensor_example">
3-
<!-- Flutter needs it to communicate with the running application
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->
66
<uses-permission android:name="android.permission.INTERNET"/>
7-
<uses-permission android:name="android.permission.WAKE_LOCK"/>
87
</manifest>

example/android/build.gradle

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
1-
group 'dev.jeremyko.proximity_sensor_example'
2-
version '1.0-SNAPSHOT'
3-
4-
buildscript {
5-
ext.kotlin_version = '1.8.22'
6-
repositories {
7-
google()
8-
mavenCentral()
9-
}
10-
11-
dependencies {
12-
classpath 'com.android.tools.build:gradle:8.1.0'
13-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14-
}
15-
}
16-
171
allprojects {
182
repositories {
193
google()
204
mavenCentral()
215
}
226
}
237

24-
rootProject.buildDir = '../build'
8+
rootProject.buildDir = "../build"
259
subprojects {
2610
project.buildDir = "${rootProject.buildDir}/${project.name}"
2711
}
2812
subprojects {
29-
project.evaluationDependsOn(':app')
13+
project.evaluationDependsOn(":app")
3014
}
3115

3216
tasks.register("clean", Delete) {

example/android/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
org.gradle.jvmargs=-Xmx1536M
1+
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
22
android.useAndroidX=true
33
android.enableJetifier=true

example/android/gradle/wrapper/gradle-wrapper.properties

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Wed Jan 25 12:09:51 EET 2023
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
57
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

example/android/settings.gradle

+22-8
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+
}()
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+
}
818

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"
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.1.0" apply false
22+
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
23+
}
24+
25+
include ":app"

example/lib/main.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import 'dart:async';
44
import 'package:proximity_sensor/proximity_sensor.dart';
55

66
class MyApp extends StatefulWidget {
7+
const MyApp({super.key});
8+
79
@override
10+
// ignore: library_private_types_in_public_api
811
_MyAppState createState() => _MyAppState();
912
}
1013

@@ -37,15 +40,17 @@ class _MyAppState extends State<MyApp> {
3740
// Add below permission in your AndroidManifest.xml file.
3841
// <uses-permission android:name="android.permission.WAKE_LOCK"/>
3942
await ProximitySensor.setProximityScreenOff(true).onError((error, stackTrace) {
40-
print("could not enable screen off functionality");
43+
if (foundation.kDebugMode) {
44+
debugPrint("could not enable screen off functionality");
45+
}
4146
return null;
4247
});
4348
// -------------------------------------------------- <ANDROID ONLY>
4449

4550
_streamSubscription = ProximitySensor.events.listen((int event) {
4651
setState(() {
4752
if (foundation.kDebugMode) {
48-
print("sensor event = ${event}");
53+
debugPrint("sensor event = $event");
4954
}
5055
_isNear = (event > 0) ? true : false;
5156
});

test/proximity_sensor_test.dart

-19
This file was deleted.

0 commit comments

Comments
 (0)