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

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

我在 运行 我的 phone 上的应用程序时出现此错误,即使在重新安装应用程序后它仍然给我这个错误:

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

我正在使用电话包通过 flutter 应用程序发送短信:

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

我使用联系人选择器,然后将号码发送到 aove 函数:

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

我用过这个包:

  telephony: ^0.1.4

android\build.gradle 看起来像这样:

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

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

发生这种情况是因为您的 gradle 和 telephony 的 gradle 之间的 kotlin-gradle-plugin 版本不匹配。

步骤

  1. 将您的 kotlin-gradle-plugin 版本升级到 1.4.10,即

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

    但是因为你 gradle 你是用一个变量来控制它,更新变量。

    ext.kotlin_version = '1.4.10'
    
  2. 重新同步您的 gradle。

  3. 现在安装您的 telephony 插件和 运行 应用程序。