From 0ad0257b1f474367a7355d145fdc3ddbbe701d1c Mon Sep 17 00:00:00 2001 From: hamzamirai Date: Wed, 2 Oct 2024 23:43:47 +0100 Subject: [PATCH 1/2] Update to Flutter 3.24.3 and fix Gradle issues on Android. --- .idea/libraries/Dart_SDK.xml | 41 +-- .idea/misc.xml | 3 + .idea/runConfigurations.xml | 13 + android/build.gradle | 22 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../social_share/SocialSharePlugin.kt | 109 +++--- example/android/app/build.gradle | 41 ++- .../android/app/src/main/AndroidManifest.xml | 3 +- example/android/build.gradle | 21 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- example/android/settings.gradle | 30 +- example/pubspec.lock | 318 ++++++++++++------ example/pubspec.yaml | 12 +- pubspec.lock | 179 ++++++---- pubspec.yaml | 4 +- 15 files changed, 515 insertions(+), 286 deletions(-) create mode 100644 .idea/runConfigurations.xml diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index f0db43fd..9907f1a5 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,26 +1,27 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 2c05ef41..b7e3e9e1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,4 +4,7 @@ + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 00000000..931b96c3 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index bb6aeb87..ddb82362 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,14 +2,14 @@ group 'com.shekarmudaliyar.social_share' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.5.30' + ext.kotlin_version = '1.9.10' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' + classpath 'com.android.tools.build:gradle:8.7.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -25,13 +25,27 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 + if (project.android.hasProperty("namespace")) { + namespace = "com.shekarmudaliyar.social_share" + } + + compileSdk = 34 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = '11' + } sourceSets { main.java.srcDirs += 'src/main/kotlin' } + defaultConfig { - minSdkVersion 16 + minSdk = 16 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 9fe8d05d..348c409e 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip diff --git a/android/src/main/kotlin/com/shekarmudaliyar/social_share/SocialSharePlugin.kt b/android/src/main/kotlin/com/shekarmudaliyar/social_share/SocialSharePlugin.kt index e3f549b3..22ba1d9b 100644 --- a/android/src/main/kotlin/com/shekarmudaliyar/social_share/SocialSharePlugin.kt +++ b/android/src/main/kotlin/com/shekarmudaliyar/social_share/SocialSharePlugin.kt @@ -30,9 +30,7 @@ import android.content.ContentValues import android.content.Context - - -class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { +class SocialSharePlugin : FlutterPlugin, MethodCallHandler, ActivityAware { private lateinit var channel: MethodChannel private var activity: Activity? = null private var activeContext: Context? = null @@ -49,9 +47,9 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { if (call.method == "shareInstagramStory" || call.method == "shareFacebookStory") { - val destination : String - val appName : String - val intentString : String + val destination: String + val appName: String + val intentString: String if (call.method == "shareInstagramStory") { destination = "com.instagram.sharedSticker" @@ -70,8 +68,12 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { val backgroundImage: String? = call.argument("backgroundImage") val backgroundVideo: String? = call.argument("backgroundVideo") - val file = File(activeContext!!.cacheDir,stickerImage) - val stickerImageFile = FileProvider.getUriForFile(activeContext!!, activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", file) + val file = File(activeContext!!.cacheDir, stickerImage) + val stickerImageFile = FileProvider.getUriForFile( + activeContext!!, + activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", + file + ) val appId: String? = call.argument("appId") val intent = Intent(intentString) @@ -85,18 +87,26 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { intent.putExtra("com.facebook.platform.extra.APPLICATION_ID", appId) } - if (backgroundImage!=null) { + if (backgroundImage != null) { //check if background image is also provided - val backfile = File(activeContext!!.cacheDir,backgroundImage) - val backgroundImageFile = FileProvider.getUriForFile(activeContext!!, activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", backfile) - intent.setDataAndType(backgroundImageFile,"image/*") + val backfile = File(activeContext!!.cacheDir, backgroundImage) + val backgroundImageFile = FileProvider.getUriForFile( + activeContext!!, + activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", + backfile + ) + intent.setDataAndType(backgroundImageFile, "image/*") } - if (backgroundVideo!=null) { + if (backgroundVideo != null) { //check if background video is also provided - val backfile = File(activeContext!!.cacheDir,backgroundVideo) - val backgroundVideoFile = FileProvider.getUriForFile(activeContext!!, activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", backfile) - intent.setDataAndType(backgroundVideoFile,"video/*") + val backfile = File(activeContext!!.cacheDir, backgroundVideo) + val backgroundVideoFile = FileProvider.getUriForFile( + activeContext!!, + activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", + backfile + ) + intent.setDataAndType(backgroundVideoFile, "video/*") } intent.putExtra("source_application", appId) @@ -104,7 +114,11 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { intent.putExtra("top_background_color", backgroundTopColor) intent.putExtra("bottom_background_color", backgroundBottomColor) // Instantiate activity and verify it will resolve implicit intent - activity!!.grantUriPermission(appName, stickerImageFile, Intent.FLAG_GRANT_READ_URI_PERMISSION) + activity!!.grantUriPermission( + appName, + stickerImageFile, + Intent.FLAG_GRANT_READ_URI_PERMISSION + ) if (activity!!.packageManager.resolveActivity(intent, 0) != null) { activeContext!!.startActivity(intent) result.success("success") @@ -118,12 +132,16 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { val intent = Intent() intent.action = Intent.ACTION_SEND - if (image!=null) { + if (image != null) { //check if image is also provided - val imagefile = File(activeContext!!.cacheDir,image) - val imageFileUri = FileProvider.getUriForFile(activeContext!!, activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", imagefile) + val imagefile = File(activeContext!!.cacheDir, image) + val imageFileUri = FileProvider.getUriForFile( + activeContext!!, + activeContext!!.applicationContext.packageName + ".com.shekarmudaliyar.social_share", + imagefile + ) intent.type = "image/*" - intent.putExtra(Intent.EXTRA_STREAM,imageFileUri) + intent.putExtra(Intent.EXTRA_STREAM, imageFileUri) } else { intent.type = "text/plain"; } @@ -132,7 +150,8 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { //create chooser intent to launch intent //source: "share" package by flutter (https://github.com/flutter/plugins/blob/master/packages/share/) - val chooserIntent: Intent = Intent.createChooser(intent, null /* dialog title optional */) + val chooserIntent: Intent = + Intent.createChooser(intent, null /* dialog title optional */) chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) activeContext!!.startActivity(chooserIntent) @@ -144,7 +163,8 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { val content: String? = call.argument("content") val image: String? = call.argument("image") - val clipboard =context!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clipboard = + context!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager if (image != null) { val values = ContentValues(2) @@ -155,7 +175,7 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { theContent.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) val clip = ClipData.newUri(theContent, "Image", imageUri) clipboard.setPrimaryClip(clip) - + } else if (content != null) { val clip = ClipData.newPlainText("", content) clipboard.setPrimaryClip(clip) @@ -164,8 +184,7 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { return } result.success("success") - } - else if (call.method == "shareWhatsapp") { + } else if (call.method == "shareWhatsapp") { //shares content on WhatsApp val content: String? = call.argument("content") val whatsappIntent = Intent(Intent.ACTION_SEND) @@ -184,7 +203,7 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { val intent = Intent(Intent.ACTION_SENDTO) intent.addCategory(Intent.CATEGORY_DEFAULT) intent.type = "vnd.android-dir/mms-sms" - intent.data = Uri.parse("sms:" ) + intent.data = Uri.parse("sms:") intent.putExtra("sms_body", content) try { activity!!.startActivity(intent) @@ -195,7 +214,12 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { } else if (call.method == "shareTwitter") { //shares content on twitter val text: String? = call.argument("captionText") - val urlScheme = "http://www.twitter.com/intent/tweet?text=${URLEncoder.encode(text, Charsets.UTF_8.name())}" + val urlScheme = "http://www.twitter.com/intent/tweet?text=${ + URLEncoder.encode( + text, + Charsets.UTF_8.name() + ) + }" Log.d("", urlScheme) val intent = Intent(Intent.ACTION_VIEW) @@ -206,8 +230,7 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { } catch (ex: ActivityNotFoundException) { result.success("error") } - } - else if (call.method == "shareTelegram") { + } else if (call.method == "shareTelegram") { //shares content on Telegram val content: String? = call.argument("content") val telegramIntent = Intent(Intent.ACTION_SEND) @@ -220,28 +243,32 @@ class SocialSharePlugin:FlutterPlugin, MethodCallHandler, ActivityAware { } catch (ex: ActivityNotFoundException) { result.success("error") } - } - else if (call.method == "checkInstalledApps") { + } else if (call.method == "checkInstalledApps") { //check if the apps exists //creating a mutable map of apps - var apps:MutableMap = mutableMapOf() + var apps: MutableMap = mutableMapOf() //assigning package manager - val pm: PackageManager =context!!.packageManager + val pm: PackageManager = context!!.packageManager //get a list of installed apps. val packages = pm.getInstalledApplications(PackageManager.GET_META_DATA) //intent to check sms app exists val intent = Intent(Intent.ACTION_SENDTO).addCategory(Intent.CATEGORY_DEFAULT) intent.type = "vnd.android-dir/mms-sms" - intent.data = Uri.parse("sms:" ) - val resolvedActivities: List = pm.queryIntentActivities(intent, 0) + intent.data = Uri.parse("sms:") + val resolvedActivities: List = pm.queryIntentActivities(intent, 0) //if sms app exists apps["sms"] = resolvedActivities.isNotEmpty() //if other app exists - apps["instagram"] = packages.any { it.packageName.toString().contentEquals("com.instagram.android") } - apps["facebook"] = packages.any { it.packageName.toString().contentEquals("com.facebook.katana") } - apps["twitter"] = packages.any { it.packageName.toString().contentEquals("com.twitter.android") } - apps["whatsapp"] = packages.any { it.packageName.toString().contentEquals("com.whatsapp") } - apps["telegram"] = packages.any { it.packageName.toString().contentEquals("org.telegram.messenger") } + apps["instagram"] = + packages.any { it.packageName.toString().contentEquals("com.instagram.android") } + apps["facebook"] = + packages.any { it.packageName.toString().contentEquals("com.facebook.katana") } + apps["twitter"] = + packages.any { it.packageName.toString().contentEquals("com.twitter.android") } + apps["whatsapp"] = + packages.any { it.packageName.toString().contentEquals("com.whatsapp") } + apps["telegram"] = + packages.any { it.packageName.toString().contentEquals("org.telegram.messenger") } result.success(apps) } else { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 0e9f6833..4d7c048f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,10 @@ +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -21,15 +28,19 @@ 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 31 + namespace = "com.shekarmudaliyar.social_share_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = "27.0.12077973" + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + kotlinOptions { + jvmTarget = JavaVersion.VERSION_11 } lintOptions { @@ -37,18 +48,15 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.shekarmudaliyar.social_share_example" - minSdkVersion 19 - targetSdkVersion 31 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + minSdk = 21 + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } buildTypes { release { - // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } @@ -60,8 +68,7 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +// testImplementation 'junit:junit:4.12' +// androidTestImplementation 'androidx.test:runner:1.1.1' +// androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 84a9b65a..8d4e0d77 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - +