我用Flutter构建了一个Android应用程序来显示用户位置,但是在添加geolocator后出现了此错误:pubspec.yaml上的'^ 4.0.0'依赖项,我尝试了其他建议,但仍然无法正常工作。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution
在android / build.gradle上
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
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
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}
在android / 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 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.salesman"
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'
}
帮助,怎么了?非常感谢您的帮助
答案 0 :(得分:1)
Android依赖项“ androidx.core:core”具有与之不同的版本 编译(1.0.0)和运行时(1.0.1)类路径。您应该手动设置 通过DependencyResolution提供相同版本
您应该尝试
gradle
版本从3.2.1更改为3.3.1 / 3.3.2 演示
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
}
如果遇到相同的问题,请添加
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.0.1"
}
}
}
}
}
答案 1 :(得分:1)
此刻,您应该将/android/build.gradle文件更改为新版本,如下所示:
ext.kotlin_version ='1.3.0'
classpath'com.android.tools.build:gradle:3.3.1'
答案 2 :(得分:0)
根据build.gradle的外观,您的项目似乎未配置为使用AndroidX。有关详情,请参见https://developer.android.com/jetpack/androidx/migrate。为此,在“重构>迁移到AndroidX”下有一个菜单选项。
答案 3 :(得分:0)
尝试一下:
1。转到gradle文件夹下的build.gradle并将类路径依赖关系更改为
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
转到android-> gradle-> wrapper-> gradle-wrapper.properties并将分发URL更改为
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip