我正在尝试构建一个新创建的Android项目(使用flutter create
创建),但是由于缺少依赖项而导致了gradle构建。
我试图安装gradle的较新版本(使用brew install gradle
),并尝试将其更改为该版本(5.4.1),但是没有运气。我还在多个地方读到,问题可能是类路径中存在不同httpclient
版本的冲突,但事实并非如此。我还尝试过将httpclient依赖关系直接添加到root 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获取吗?
答案 0 :(得分:0)
将buildscript
更改为:
buildscript {
repositories {
maven {url "https://maven.google.com"}
// google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.4.0"
}
}