【问题标题】:Flutter Error: A problem occurred configuring project ':telephony'Flutter 错误:配置项目“:电话”时出现问题
【发布时间】:2021-05-24 13:18:16
【问题描述】:

我在手机上运行应用程序时遇到此错误,即使重新安装应用程序后仍然给我此错误:

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 App发送短信:

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

【问题讨论】:

  • 看起来那个版本的 kotlin-gradle-plugin 没有成功下载。请检查您的互联网连接,然后重试。
  • 互联网运行良好,我也尝试了多次,但仍然出现相同的错误
  • 不,它没有帮助,当我删除电话包时,应用程序运行正常
  • 尝试将您的 kotlin 版本升级到 1.4.10 ext.kotlin_version = '1.4.10' 并首先重新同步 gradle,然后安装电话包

标签: flutter dart telephony


【解决方案1】:

这是因为您的 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 插件并运行应用程序。

【讨论】:

    猜你喜欢
    • 2020-10-07
    • 2020-08-23
    • 2021-01-09
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2022-12-17
    相关资源
    最近更新 更多