在Android Studio 3.4中。
在gradle.properties中:
android.useAndroidX=true
android.enableJetifier=true
在app / build.gradle中:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
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'
}
活动中:
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.ui.AppBarConfiguration
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appBarConfiguration = AppBarConfiguration(navController.graph)
}
}
但是我在这一行中遇到编译错误:
import androidx.navigation.ui.AppBarConfiguration
错误消息:
Unresolved reference: navigation
答案 0 :(得分:1)
我相信您不见了:
implementation "androidx.navigation:navigation-fragment-ktx:2.1.0-alpha05"
implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha05"