【问题标题】:Newly created Flutter / Android project fails to build新创建的 Flutter/Android 项目构建失败
【发布时间】:2019-09-22 23:01:44
【问题描述】:

我正在尝试构建一个新创建的 Android 项目(使用 flutter create 创建),但由于缺少依赖项而导致 gradle 构建。

我尝试安装更新版本的 gradle(使用brew install gradle)并尝试将其更改为该(5.4.1)版本,但没有运气。我还在多个地方读到,问题可能是类路径中不同httpclient 版本的冲突,但事实并非如此。我也尝试过将httpclient依赖直接添加到根build.gradle文件中,但错误仍然存​​在。

build.grade (root)

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
                // classpath 'org.apache.httpcomponents:httpclient:4.5.8'
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

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
}

android/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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.myapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

预期结果:build finished。

实际结果:gradle build 异常;

[   +3 ms] * Error running Gradle:
           ProcessException: Process "/Users/riccardo/dev/app/android/gradlew" exited abnormally:

           FAILURE: Build failed with an exception.

           * What went wrong:
           A problem occurred configuring root project 'android'.
           > Could not resolve all artifacts for configuration ':classpath'.
              > Could not resolve com.android.tools.build:gradle:2.3.0.
                Required by:
                    project :
                 > Could not resolve com.android.tools.build:gradle:2.3.0.
                    > Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory
                 > Could not resolve com.android.tools.build:gradle:2.3.0.
                    > Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory

如何安装这个缺失的依赖项?例如不应该从 jcenter 获取它吗?

【问题讨论】:

    标签: android gradle flutter android-gradle-plugin


    【解决方案1】:

    将buildscript 更改为:

    buildscript {
        repositories {
            maven {url "https://maven.google.com"}
            // google()
            jcenter()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:3.4.0"
        }
    }
    

    【讨论】:

    • 出现完全相同的错误(显然 2.3.0 被 3.4.0 取代)。
    • @riccardo_92 2.3.0 不知道存储库 google()... 我什至不认为 Flutter 项目是“新的”,当它使用这些过时的版本时。 current version 是 1.2.1。
    • 我像你说的那样使用了 3.4.0。 Flutter 项目于今天创建。
    • @riccardo_92 "created today" 与 Flutter 版本关系不大。可能需要安装或更新 gradle(包装器)。
    • 清除;我今天还安装了最新的 Flutter lib。我会尝试更新 gradle 包装器。
    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2021-05-09
    • 2021-12-07
    • 2016-04-09
    • 2019-05-17
    • 1970-01-01
    • 2023-02-02
    相关资源
    最近更新 更多