Gradle build fails when using google_sign_in plugin for flutter
325
change the Gradle version in the google_sign_in build.gradle file to match with the one in the android folder in the flutter app.
after run flutter clean.
then run your project.
Author by
TheEggHealer
Updated on December 26, 2022Comments
-
TheEggHealer over 1 year
The app compiles fine when not using the plugin (google_sign_in). But as soon as I add it as a dependency in the pubspec.yaml, the app won't build.
This is the gradle error I get:
* What went wrong: A problem occurred configuring project ':google_sign_in'. > Could not resolve all artifacts for configuration ':google_sign_in:classpath'. > Could not find kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.3.11). Searched in the following locations: https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.11/kotlin-reflect-1.3.11.jar > Could not get unknown property 'android' for project ':google_sign_in' of type org.gradle.api.Project.
I have tried clicking the link to kotlin-reflect-1.3.11.jar and it downloads the file, so the link clearly works.
I have tried messing around with different versions of almost everything, but I haven't found anything that works...
Here is my pubspec.yaml file:
name: wishtogether description: A new Flutter application. publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: sdk: ">=2.7.0 <3.0.0" dependencies: flutter: sdk: flutter firebase_core: 0.5.3 firebase_auth: ^0.18.4+1 google_sign_in: ^4.5.6 provider: ^4.3.2+3 cupertino_icons: ^0.1.3 dev_dependencies: flutter_test: sdk: flutter flutter: uses-material-design: true
Project-level build.gradle:
buildscript { ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.5.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.2.0' //4.3.4 } } allprojects { repositories { google() jcenter() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
App-level build.gradle
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } 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.google.gms.google-services' //Firebase apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 29 sourceSets { main.java.srcDirs += 'src/main/kotlin' } lintOptions { disable 'InvalidPackage' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.jonathan.wishtogether" minSdkVersion 23 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } 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 } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation platform('com.google.firebase:firebase-bom:26.2.0') implementation 'com.google.firebase:firebase-analytics' }
Any suggestions or ideas as to what may be wrong? Thanks!
-
TheEggHealer over 3 yearsWhere do I find the shared preferences build.gradle? And why would that be a problem since I'm not even using shared preferences?
-
TheEggHealer over 3 yearsI solved it by going to the google_sign_in's build.gradle and changed the gradle version to match mine. For others who may have trouble finding it, this is the path: flutter_sdk/.pub-cache/hosted/pub.dartlang.org/google_sign_in-4.5.6/android. If @Tharaka Dayanjana change it from shared preferences to google_sign_in I can mark the answer as the solution.