프로젝트 ': app'의 종속성 'com.android.support:support-annotations'와 충돌합니다. 앱 (26.1.0) 및 테스트 앱 (27.1.1)의 해결 된 버전이 다릅니다.
Android 앱 개발을 처음 사용합니다. 새 프로젝트를 만들려고 할 때 Android Project ... 다음과 같은 메시지가 뜹니다 ..
오류 : ': app : preDebugAndroidTestBuild'작업에 대한 실행이 실패했습니다.
프로젝트 ': app'의 종속성 'com.android.support:support-annotations'와 충돌합니다. 앱 (26.1.0) 및 테스트 앱 (27.1.1)의 해결 된 버전이 다릅니다. 자세한 내용은 https://d.android.com/r/tools/test-apk-dependency-conflicts.html 을 참조하십시오. 정보 : Gradle 작업 [: app : generateDebugSources, : app : generateDebugAndroidTestSources, : app : mockableAndroidJar]
이것은 내 프로젝트의 스크린 샷입니다. 여기를 클릭하여 발생한 오류의 스크린 샷을 확인하십시오.
나는 또한이 코드를 내 의존성에 추가하려고 시도했습니다. androidTestCompile 'com.android.support:support-annotations:23.3.0'이것은 작동하지 않았습니다. 나는 또한 27.1.1과 26.1.0 ..을 시도했지만 역시 효과가 없었다.
스크린 샷을 기반으로 두 가지 작동하는 솔루션을 찾았습니다.
첫 번째 솔루션 :이 줄에 gradle 모듈의 종속성에 추가
compile 'com.android.support:support-annotations:27.1.1'
프로젝트 동기화
참고 : Android 스튜디오 3 이상을 사용 compile
하는 경우implementation
두 번째 솔루션 : https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties 문서에있는 프로젝트 전체 속성 구성
프로젝트 gradle에서 다음 줄을 추가하십시오.
// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
// The following are only a few examples of the types of properties you can define.
compileSdkVersion = 26
// You can also use this to specify versions for dependencies. Having consistent
// versions between modules can avoid behavior conflicts.
supportLibVersion = "27.1.1"
}
그런 다음이 섹션에 액세스하려면 compileSdkVersion
줄을
compileSdkVersion rootProject.ext.compileSdkVersion
과에서 dependencies
섹션 이렇게 될 가져온 라이브러리를 변경 :
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
프로젝트 동기화
참고 : Android 스튜디오 3 이상을 사용 compile
하는 경우implementation
간의 차이 compile
및 implementation
이 봐 Gradle을의 구현 및 컴파일의 차이점은 무엇입니까
depencencies 블록 앞에 app.gradle 파일에 아래 행을 추가하십시오.
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
더 나은 이해를 위해 아래 스크린 샷도 있습니다.
configuration.all 블록은 대상 sdk를 26으로 설정하려는 경우에만 유용합니다. 27로 변경할 수 있으면 app.gradle 파일에 구성 블록을 추가하지 않고도 오류가 사라집니다.
app.gradle 파일에서 모든 테스트 구현을 제거하면 오류가 해결되고 여기에서 구성 블록을 추가 할 필요가 없으며 targetsdk 버전을 변경할 필요도 없습니다.
도움이 되었기를 바랍니다.
버전 26 을 사용하는 경우 내부 종속성 버전은 1.0.1 및 3.0.1 이어야합니다. 즉, 다음과 같이
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
버전 27 을 사용하는 경우 내부 종속성 버전은 다음과 같이 1.0.2 및 3.0.2 여야 합니다.
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Android Studio 3.1. + 이상을 사용하는 경우
gradle depedencies에 이것을 넣으십시오.
implementation 'com.android.support:support-annotations:27.1.1'
전반적으로 다음과 같습니다.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
implementation 'com.android.support:support-annotations:27.1.1'
}
이는 버전 충돌로 인한 것입니다.이를 해결하려면 지원 주석 버전을 강제로 업데이트하고 모듈에 다음 행을 추가하십시오. app gradle
implementation ('com.android.support:support-annotations:27.1.1')
이것이 문제를 해결하기를 바랍니다.)
편집하다
거의 잊었습니다 . 버전에 대해 단일 추가 속성 ( https://docs.gradle.org/current/userguide/writing_build_scripts.html#sec:extra_properties )을 선언하고 프로젝트 (또는 최상위) gradle 파일로 이동 한 다음 지원을 선언하거나이 예제의 경우 주석 버전 var
ext.annotation_version = "27.1.1"
그런 다음 모듈 gradle에서 다음으로 바꿉니다.
implementation ("com.android.support:support-annotations:$annotation_version")
이것은 @emadabel 솔루션과 매우 유사하지만 블록이나 rootproject
접두사 가없는 좋은 대안입니다 .
이것을 build.gradle (Module 앱)에 추가하면 나를 위해 일했습니다.
컴파일 'com.android.support:support-annotations:27.1.1'
걱정하지 마십시오. 간단합니다.
"Project"디렉토리 구조로 이동하여 "Gradle Scripts"로 이동하고 그 안에 "build.gradle (Module : app)"로 이동하여 두 번 클릭합니다.
이제-프로그램을 아래로 스크롤하고 종속성 섹션으로 이동하십시오.
종속성 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
}
이제 마지막 두 줄의 코드를 삭제하고 앱을 다시 빌드하면 이제 작동합니다.
종속성은 다음과 같아야합니다.
종속성 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
}
앱을 다시 빌드하면 작동합니다!
프로젝트의 build.gradle (Module App)으로 이동합니다.
그림을 따라 해당 버전을 변경하십시오.
compileSdkVersion: 27
targetSdkVersion: 27
그리고 안드로이드 스튜디오 버전 2 : 다음 줄로 줄을 변경하십시오.
compile 'com.android.support:appcompat-v7:27.1.1'
else 다음 줄로 줄을 변경하십시오.
implementation 'com.android.support:appcompat-v7:27.1.1'
그리고 바라건대 버그를 해결할 것입니다.
이것을 gradle 파일에 추가하십시오.
implementation 'com.android.support:support-annotations:27.1.1'
이 문제를 해결하는 또 다른 간단한 방법은 build.gradle
(앱) 을 편집하는 것입니다 .
- 이동
android
태그와 변화compileSdkVersion 26
에compileSdkVersion 27
- 이동
defaultConfig
태그와 변화targetSdkVersion 26
에targetSdkVersion 27
- Got to
dependencies
tag and changeimplementation 'com.android.support:appcompat-v7:26.1.0'
toimplementation 'com.android.support:appcompat-v7:27.1.1'
I have the same problem, in build.gradle (Module:app) add the following line of code inside dependencies:
dependencies
{
...
compile 'com.android.support:support-annotations:27.1.1'
}
It worked for me perfectly
Important Update
Go to project level build.gradle, define global variables
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlinVersion = '1.2.61'
ext.global_minSdkVersion = 16
ext.global_targetSdkVersion = 28
ext.global_buildToolsVersion = '28.0.1'
ext.global_supportLibVersion = '27.1.1'
}
Go to app level build.gradle, and use global variables
app build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
some library build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
The solution is to make your versions same as in all modules. So that you don't have conflicts.
Important Tips
I felt when I have updated versions of everything- gradle, sdks, libraries etc. then I face less errors. Because developers are working hard to make it easy development on Android Studio.
Always have latest but stable versions Unstable versions are alpha
, beta
and rc
, ignore them in developing.
I have updated all below in my projects, and I don't face these errors anymore.
- Update Android Studio (Track release)
- Project level
build.gradle
-classpath 'com.android.tools.build:gradle:3.2.0'
(Trackandroid.build.gradle
release & this) - Have updated
buildToolVersion
(Track buildToolVersion release) - Have latest
compileSdkVersion
andtargetSdkVersion
Track platform release - Have updated library versions, because after above updates, its necessary. (@See How to update)
Happy coding! :)
If changing target sdk version doesn't help then if you have any dependency with version 3.0.2
then change it to 3.0.1
.
e.g change
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
to
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
A better solution is explained in the official explanation. I left the answer I have given before under the horizontal line.
According to the solution there:
Use an external tag and write down the following code below in the top-level build.gradle file. You're going to change the version to a variable rather than a static version number.
ext {
compileSdkVersion = 26
supportLibVersion = "27.1.1"
}
Change the static version numbers in your app-level build.gradle file, the one has (Module: app)
near.
android {
compileSdkVersion rootProject.ext.compileSdkVersion // It was 26 for example
// the below lines will stay
}
// here there are some other stuff maybe
dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
// the below lines will stay
}
Sync your project and you'll get no errors.
You don't need to add anything to Gradle scripts. Install the necessary SDKs and the problem will be solved.
In your case, install the libraries below from Preferences > Android SDK or Tools > Android > SDK Manager
gradle 파일의 종속성 아래에이 줄을 추가하십시오.
compile 'com.android.support:support-annotations:27.1.1'
'code' 카테고리의 다른 글
WinForms 응용 프로그램에 명령 줄 인수를 어떻게 전달합니까? (0) | 2020.08.29 |
---|---|
두 숫자 목록 간의 코사인 유사성 (0) | 2020.08.29 |
javascript / Node.js에서 시간을 어떻게 얻습니까? (0) | 2020.08.29 |
URL에서 .html을 제거하는 방법? (0) | 2020.08.29 |
Go 언어로 UUID를 생성하는 방법이 있습니까? (0) | 2020.08.29 |