Fixed gradle error on build

This commit is contained in:
dstark5
2024-11-01 19:07:48 +05:30
parent 2df0d1f655
commit 7b6394f6ad
9 changed files with 121 additions and 111 deletions

View File

@ -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 = "../.."
}

View File

@ -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,12 +5,12 @@ 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) {

View File

@ -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

View File

@ -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"

View File

@ -35,7 +35,8 @@ class OpenLibrary extends TrendingBooksImpl {
@override
List<TrendingBookData> _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<TrendingBookData> trendingBooks = [];
for (var element in bookList) {
if (element.querySelector('h3[class="booktitle"]')?.text != null &&

View File

@ -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<void> 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<String> saveAndGetImagePath(String url) async {
if (url != null && url.isNotEmpty) {
try {
final imageProvider = CachedNetworkImageProvider(url);
final imageStream = imageProvider.resolve(const ImageConfiguration());
String? localFilePath;
final Completer<ByteData> 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 "";
}
}

View File

@ -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,
),
);

View File

@ -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:

View File

@ -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