From 7b6394f6ad54752b3c5b78b104456218617ff127 Mon Sep 17 00:00:00 2001 From: dstark5 <136567021+dstark5@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:07:48 +0530 Subject: [PATCH] Fixed gradle error on build --- android/app/build.gradle | 85 ++++++------------- android/build.gradle | 19 +---- .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/settings.gradle | 30 +++++-- lib/services/open_library.dart | 3 +- lib/services/share_book.dart | 66 +++++++++++--- lib/ui/themes.dart | 18 ++-- pubspec.lock | 8 -- pubspec.yaml | 1 - 9 files changed, 121 insertions(+), 111 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index d03b2ad..1e822b1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,75 +1,49 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } +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 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) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - - def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } - android { - namespace "com.app.openlib" - compileSdkVersion flutter.compileSdkVersion - ndkVersion flutter.ndkVersion + namespace = "com.app.openlib" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + jvmTarget = JavaVersion.VERSION_17 } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.app.openlib" + applicationId = "com.app.openlib" // You can update the following values to match your application needs. - // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger() - targetSdkVersion flutter.targetSdkVersion - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } signingConfigs { release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null - storePassword keystoreProperties['storePassword'] - v1SigningEnabled true - v2SigningEnabled true + keyAlias = keystoreProperties['keyAlias'] + keyPassword = keystoreProperties['keyPassword'] + storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword = keystoreProperties['storePassword'] + v1SigningEnabled = true + v2SigningEnabled = true } } @@ -77,18 +51,13 @@ android { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - // replace with "debug" when running on debug version - signingConfig signingConfigs.release - minifyEnabled false - shrinkResources false + signingConfig = signingConfigs.release + minifyEnabled = false + shrinkResources = false } } } flutter { - source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + source = "../.." } \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index f7eb7f6..8e9de9d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,16 +1,3 @@ -buildscript { - ext.kotlin_version = '1.7.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() @@ -18,14 +5,14 @@ allprojects { } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 3c472b9..41681a7 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-7.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip \ No newline at end of file diff --git a/android/settings.gradle b/android/settings.gradle index 44e62bc..cdeb073 100644 --- a/android/settings.gradle +++ b/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.0.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.0" apply false +} + +include ":app" \ No newline at end of file diff --git a/lib/services/open_library.dart b/lib/services/open_library.dart index 144b431..12fbb01 100644 --- a/lib/services/open_library.dart +++ b/lib/services/open_library.dart @@ -35,7 +35,8 @@ class OpenLibrary extends TrendingBooksImpl { @override List _parser(data) { var document = parse(data.toString()); - var bookList = document.querySelectorAll('li[class="searchResultItem"]'); + var bookList = + document.querySelectorAll('li[class="searchResultItem sri--w-main"]'); List trendingBooks = []; for (var element in bookList) { if (element.querySelector('h3[class="booktitle"]')?.text != null && diff --git a/lib/services/share_book.dart b/lib/services/share_book.dart index 9d7edd3..c15a372 100644 --- a/lib/services/share_book.dart +++ b/lib/services/share_book.dart @@ -1,23 +1,67 @@ +import 'dart:async'; import 'dart:io'; +import 'dart:typed_data'; +import 'dart:ui'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:share_plus/share_plus.dart'; -import 'package:http/http.dart' as http; Future shareBook(String title, String link, String path) async { try { - final url = Uri.parse(path); - final response = await http.get(url); - final bytes = response.bodyBytes; - - //temp - final temp = await getTemporaryDirectory(); - final dest = '${temp.path}/image.jpg'; - File(dest).writeAsBytes(bytes); - + String imagePath = await saveAndGetImagePath(path); String message = 'Discover this amazing book: "$title"\nRead more : $link'; - await Share.shareXFiles([XFile(dest)], text: message); + if (imagePath.isNotEmpty) { + await Share.shareXFiles([XFile(imagePath)], text: message); + } else { + await Share.share(message); + } } catch (e) { debugPrint('Error sharing the book: $e'); } } + +Future saveAndGetImagePath(String url) async { + if (url != null && url.isNotEmpty) { + try { + final imageProvider = CachedNetworkImageProvider(url); + final imageStream = imageProvider.resolve(const ImageConfiguration()); + String? localFilePath; + + final Completer completer = Completer(); + + imageStream.addListener( + ImageStreamListener( + (ImageInfo info, bool _) async { + try { + final ByteData? byteData = + await info.image.toByteData(format: ImageByteFormat.png); + if (byteData != null) { + final Uint8List imageBytes = byteData.buffer.asUint8List(); + final Directory tempDir = await getTemporaryDirectory(); + final File imageFile = File('${tempDir.path}/image.jpg'); + + await imageFile.writeAsBytes(imageBytes); + localFilePath = imageFile.path; + completer.complete(byteData); + } else { + completer.completeError('Failed to get image bytes'); + } + } catch (e) { + completer.completeError(e); + } + }, + onError: (exception, stackTrace) { + completer.completeError('Failed to get image bytes'); + }, + ), + ); + await completer.future; + return localFilePath ?? ""; + } catch (e) { + return ""; + } + } else { + return ""; + } +} diff --git a/lib/ui/themes.dart b/lib/ui/themes.dart index f3fba92..346c375 100644 --- a/lib/ui/themes.dart +++ b/lib/ui/themes.dart @@ -7,11 +7,13 @@ import 'package:google_fonts/google_fonts.dart'; // Project imports: import 'package:openlib/ui/extensions.dart'; +final secondaryColor = '#FB0101'.toColor(); + ThemeData lightTheme = ThemeData( primaryColor: Colors.white, colorScheme: ColorScheme.light( primary: Colors.white, - secondary: '#FB0101'.toColor(), + secondary: secondaryColor, tertiary: Colors.black, tertiaryContainer: '#F2F2F2'.toColor(), ), @@ -36,18 +38,20 @@ ThemeData lightTheme = ThemeData( fontFamily: GoogleFonts.nunito().fontFamily, useMaterial3: true, textSelectionTheme: TextSelectionThemeData( - selectionColor: '#FB0101'.toColor(), - selectionHandleColor: '#FB0101'.toColor(), + selectionColor: secondaryColor, + selectionHandleColor: secondaryColor, ), ); ThemeData darkTheme = ThemeData( primaryColor: Colors.black, + scaffoldBackgroundColor: Colors.black, colorScheme: ColorScheme.dark( primary: Colors.black, - secondary: '#FB0101'.toColor(), + secondary: secondaryColor, tertiary: Colors.white, - tertiaryContainer: '#2B2B2B'.toColor(), + tertiaryContainer: '#141414'.toColor(), + surface: Colors.black, ), textTheme: TextTheme( displayLarge: const TextStyle( @@ -71,7 +75,7 @@ ThemeData darkTheme = ThemeData( fontFamily: GoogleFonts.nunito().fontFamily, useMaterial3: true, textSelectionTheme: TextSelectionThemeData( - selectionColor: '#FB0101'.toColor(), - selectionHandleColor: '#FB0101'.toColor(), + selectionColor: secondaryColor, + selectionHandleColor: secondaryColor, ), ); diff --git a/pubspec.lock b/pubspec.lock index d0f1d18..ba9535e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -358,14 +358,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.5.3" - flutter_share: - dependency: "direct main" - description: - name: flutter_share - sha256: ae12c1cea13b35926a109824ffac601531e40cb94ad53eeae58625eceb3eaaaa - url: "https://pub.dev" - source: hosted - version: "2.0.0" flutter_svg: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index b1b5435..9ec5334 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -66,7 +66,6 @@ dependencies: http: ^1.2.2 path: ^1.9.0 share_plus: ^10.1.0 - flutter_share: ^2.0.0 dev_dependencies: import_sorter: ^4.6.0