diff --git a/android/build.gradle b/android/build.gradle index 1a1c7b3..8f46c70 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,14 +2,14 @@ group 'com.homex.open_mail_app' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.9.21' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' + classpath 'com.android.tools.build:gradle:8.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -25,13 +25,22 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 31 + compileSdk 33 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { - minSdkVersion 16 + minSdkVersion 21 } lintOptions { disable 'InvalidPackage' @@ -40,5 +49,5 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.google.code.gson:gson:2.8.5' + implementation 'com.google.code.gson:gson:2.10.1' } diff --git a/android/src/main/kotlin/com/homex/open_mail_app/OpenMailAppPlugin.kt b/android/src/main/kotlin/com/homex/open_mail_app/OpenMailAppPlugin.kt index 3661323..6bc41bb 100644 --- a/android/src/main/kotlin/com/homex/open_mail_app/OpenMailAppPlugin.kt +++ b/android/src/main/kotlin/com/homex/open_mail_app/OpenMailAppPlugin.kt @@ -1,5 +1,6 @@ package com.homex.open_mail_app +import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.pm.LabeledIntent @@ -13,44 +14,24 @@ import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import io.flutter.plugin.common.PluginRegistry.Registrar class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler { private lateinit var channel: MethodChannel private lateinit var applicationContext: Context - override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { // Although getFlutterEngine is deprecated we still need to use it for // apps not updated to Flutter Android v2 embedding - channel = MethodChannel(flutterPluginBinding.flutterEngine.dartExecutor, "open_mail_app") + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "open_mail_app") channel.setMethodCallHandler(this) init(flutterPluginBinding.applicationContext) } - // This static function is optional and equivalent to onAttachedToEngine. It supports the old - // pre-Flutter-1.12 Android projects. You are encouraged to continue supporting - // plugin registration via this function while apps migrate to use the new Android APIs - // post-flutter-1.12 via https://flutter.dev/go/android-project-migration. - // - // It is encouraged to share logic between onAttachedToEngine and registerWith to keep - // them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called - // depending on the user's project. onAttachedToEngine or registerWith must both be defined - // in the same class. - companion object { - @JvmStatic - fun registerWith(registrar: Registrar) { - val channel = MethodChannel(registrar.messenger(), "open_mail_app") - val plugin = OpenMailAppPlugin() - channel.setMethodCallHandler(plugin) - plugin.init(registrar.context()) - } - } - - fun init(context: Context) { + private fun init(context: Context) { applicationContext = context } - override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + override fun onMethodCall(call: MethodCall, result: Result) { if (call.method == "openMailApp") { val opened = emailAppIntent(call.argument("nativePickerTitle") ?: "") result.success(opened) @@ -72,11 +53,11 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler { } } - override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) } - private fun emailAppIntent(@NonNull chooserTitle: String): Boolean { + private fun emailAppIntent(chooserTitle: String): Boolean { val emailIntent = Intent(Intent.ACTION_VIEW, Uri.parse("mailto:")) val packageManager = applicationContext.packageManager @@ -113,7 +94,8 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler { } } - private fun composeNewEmailAppIntent(@NonNull chooserTitle: String, @NonNull contentJson: String): Boolean { + @SuppressLint("IntentReset") + private fun composeNewEmailAppIntent(chooserTitle: String, contentJson: String): Boolean { val packageManager = applicationContext.packageManager val emailContent = Gson().fromJson(contentJson, EmailContent::class.java) val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")) @@ -183,7 +165,8 @@ class OpenMailAppPlugin : FlutterPlugin, MethodCallHandler { return true } - private fun composeNewEmailInSpecificEmailAppIntent(@NonNull name: String, @NonNull contentJson: String): Boolean { + @SuppressLint("IntentReset") + private fun composeNewEmailInSpecificEmailAppIntent(name: String, contentJson: String): Boolean { val packageManager = applicationContext.packageManager val emailContent = Gson().fromJson(contentJson, EmailContent::class.java) val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index a4d6944..1dca480 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,10 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { @@ -21,13 +23,8 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion flutter.compileSdkVersion - + compileSdkVersion 35 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -44,7 +41,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.homex.open_mail_app_example" - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName @@ -57,12 +54,10 @@ android { signingConfig signingConfigs.debug } } + namespace 'com.homex.open_mail_app_example' } flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 77a8eb1..f880684 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 607849b..fdca676 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + + diff --git a/example/android/build.gradle b/example/android/build.gradle index 1743f09..3c29d0d 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,21 +1,19 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() mavenCentral() } + subprojects { + afterEvaluate { project -> + if (project.hasProperty('android')) { + project.android { + if (namespace == null) { + namespace project.group + } + } + } + } + } } rootProject.buildDir = '../build' @@ -26,6 +24,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 94adc3a..b9a9a24 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,3 +1,6 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index b8793d3..15de902 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..b723ac3 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.2.1" apply false + id "org.jetbrains.kotlin.android" version "1.9.21" apply false +} + +include ":app" \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 33fa3d0..64bb8f7 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,7 +8,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: '^3.0.0' + flutter: ">=3.7.0" dependencies: flutter: @@ -24,7 +25,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.6 dev_dependencies: flutter_test: diff --git a/pubspec.yaml b/pubspec.yaml index 2e0a265..a845d6e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,12 +4,12 @@ version: 0.4.4 homepage: https://github.com/HomeXLabs/open-mail-app-flutter environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.12.0" + sdk: '^3.0.0' + flutter: ">=3.7.0" dependencies: - platform: ^3.1.0 - url_launcher: ^6.0.2 + platform: ^3.1.4 + url_launcher: ^6.2.3 flutter: sdk: flutter