Search code examples
flutterdarttelephony

Flutter Error: A problem occurred configuring project ':telephony'


I am getting this error while running the app on my phone, Even after reinstalling App it is still giving me this error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':telephony'.
> Could not resolve all artifacts for configuration ':telephony:classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10.
     Required by:
         project :telephony
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.4.10/kotlin-gradle-plugin-1.4.10.pom'. Received status code 502 from server: Bad Gateway
> Could not get unknown property 'android' for project ':telephony' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 18s
Exception: Gradle task assembleDebug failed with exit code 1

I am using telephony package to send SMS through flutter App:

final Telephony telephony = Telephony.instance;
  void sendSMS(String number)
  {
    telephony.sendSms(to: number, message: "Hey");
  }

I used contact picker and then sent the number to the aove function:

List <String> num = contact.phoneNumber.toString().split(' ');
                        print(num);
                        print(num[0]);
                        sendSMS(num[0]);

I used this package:

  telephony: ^0.1.4

android\build.gradle looks like this:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.8'
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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\build.gradle is:

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.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    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.example.epicare"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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 platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-analytics'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Solution

  • This is happening due to a version mismatch of the kotlin-gradle-plugin between your gradle and the gradle of the telephony.

    Steps

    1. Upgrade your kotlin-gradle-plugin version to 1.4.10, i.e.,

      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10"
      

      But since in you gradle you are conntrolling it with a variable, update the variable.

      ext.kotlin_version = '1.4.10'
      
    2. Resync your gradle.

    3. Now install your telephony plugin and run the app.