My Android app has been working fine up until now in Android Studio, but when I add these lines of code to my Android Studio project to try and use Android's Navigation Component (https://developer.android.com/guide/navigation/navigation-getting-started), I keeping getting gradle errors.
// Navigation Component
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
One of these errors is about dialogCornerRadius not found:
.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0.aar/dd9096ce87096c8058dc92354e7f3db2/res/values-v28/values-v28.xml
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
I have read on other posts that the problem is related to my compile sdk version, but I'm having trouble figuring out how to change my app build.gradle code to solve the problem:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def support_version = "26.1.0"
def nav_version = "2.1.0"
// Navigation Component
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Added to avoid dependency conflict
implementation 'com.android.support:support-annotations:27.1.1'
// Added to use tab layouts in MainActivity
implementation 'com.android.support:design:26.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation "com.android.support:support-v4:$support_version"
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'
}
When I try to change the line
implementation 'com.android.support:support-annotations:27.1.1'
I get different gradle errors. (I thought that might work though since it seems to be where the different version is). The error is:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
I followed the link in the error for this and am still lost.
Would anyone be able to help me with this? Thank you in advance.