Android 依赖 'com.android.support:support-v4' 的编译 (26.1.0) 和运行时 (27.1.1) 类路径错误的版本不同
Posted
技术标签:
【中文标题】Android 依赖 \'com.android.support:support-v4\' 的编译 (26.1.0) 和运行时 (27.1.1) 类路径错误的版本不同【英文标题】:Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0) and runtime (27.1.1) classpath errorAndroid 依赖 'com.android.support:support-v4' 的编译 (26.1.0) 和运行时 (27.1.1) 类路径错误的版本不同 【发布时间】:2019-05-10 02:36:42 【问题描述】:我将 firebase admob 添加到我的应用程序中,我已将 google 服务文件添加到应用程序文件夹。它显示此错误。请帮助我解决此问题。平台颤动。
运行:
flutter run
Using hardware rendering with device SM G615F. If you get graphics
artifacts, consider enabling software rendering with "--enable-software-
rendering".
Launching lib/main.dart on SM G615F in debug mode...
Initializing gradle... 3.0s
Resolving dependencies... 10.2s
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedResFolders(FileCollection)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> android dependency 'com.android.support:support-v4' has different version
for the compile (26.1.0) and runtime (27.1.1) classpath. You should manually
set the same version via DependencyResolution
* 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 8s
Gradle task 'assembleDebug'... Done 8.9s
Gradle task assembleDebug failed with exit code 1
build.gradle:
buildscript
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0' // google-services
plugin
allprojects
repositories
google()
jcenter()
maven
url "https://maven.google.com"
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
subprojects
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
pubspec.yaml:
name: avengersquiz
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1 #comment these 2 in case issues
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for ios style icons.
cupertino_icons: ^0.1.2
share: ^0.5.3
flutter_webview_plugin: ^0.3.0+2
launch_review: ^1.0.1
material_design_icons_flutter: ^2.7.94
shared_preferences: ^0.4.3
dio: ^1.0.6
flutter_downloader: ^1.0.6
path_provider: ^0.4.1
simple_permissions: ^0.1.9 #oreo fix
http: ^0.12.0
fluttertoast: ^2.1.3
flutter_staggered_grid_view: ^0.2.4 #any
flutter_local_notifications: ^0.4.2
url_launcher: any
flutter_custom_tabs: ^0.4.0
vibrate: ^0.0.4
splashscreen: ^1.1.0
nima: ^1.0.0
flare_flutter: ^1.0.0
firebase_admob: ^0.7.0 #0.5.2
firebase_analytics: ^1.0.6
dev_dependencies:
flutter_test:
sdk: flutter
build.gradle/app:
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"
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
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.package"
minSdkVersion 16 //21
targetSdkVersion 28
versionCode 1
versionName "1.1"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
signingConfigs
release
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
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.release
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'
apply plugin: 'com.google.gms.google-services'
将其添加到我的项目/gradle 后:
subprojects
project.configurations.all
resolutionStrategy.eachDependency details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') )
details.useVersion "26.1.0"
我收到了这个错误:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'android.arch.lifecycle:runtime' has different version
for the compile (1.0.0) and runtime (1.1.0) classpath. You should manually
set
the same version via DependencyResolution
* 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 27s
Gradle task 'assembleDebug'... Done 28.3s
Gradle task assembleDebug failed with exit code 1
【问题讨论】:
【参考方案1】:在你的 build.gradle - in end -After -
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"
【讨论】:
看到我在将此代码添加到项目/gradle 后收到此错误【参考方案2】:我发现我在包含flutter_downloader时遇到了同样的错误,删除它,错误就消失了。
Android 依赖 'android.arch.core:runtime' 对于编译 (1.1.0) 和运行时 (1.1.1) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本
【讨论】:
以上是关于Android 依赖 'com.android.support:support-v4' 的编译 (26.1.0) 和运行时 (27.1.1) 类路径错误的版本不同的主要内容,如果未能解决你的问题,请参考以下文章
NoClassDefFoundError: android.support.v7.widget.helper.ItemTouchHelper$3
Android Gradle 插件Android 依赖管理 ⑥ ( 依赖冲突处理 | transitive 依赖传递设置 | exclude 依赖排除设置 | force 强制指定依赖库 )