簡體   English   中英

新創建的Flutter / Android項目無法構建

[英]Newly created Flutter / Android project fails to build

我正在嘗試構建一個新創建的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構建異常;

[   +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獲取它嗎?

buildscript更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM