我需要在使用Android导航和动态功能的应用中添加对androidx的依赖项。fragment:fragment-ktx:1.3.0-beta 01。我需要依赖项来调用setFragmentResult
,但应用将停止工作,出现异常
“找不到类别定义”
在运行时。请帮助...
更新
这是我的应用程序构建gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
android {
compileSdkVersion 29
defaultConfig {
applicationId "it.kfi.lorikeetmobile"
minSdkVersion 25
targetSdkVersion 29
versionCode 2
versionName "1.0b"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
/*javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.incremental":"true",
"room.expandProjection":"true"]
}
}*/
}
//kotlin DSL
// configurations.all {
// resolutionStrategy {
// force("org.antlr:antlr4-runtime:4.7.1")
// force("org.antlr:antlr4-tool:4.7.1")
// }
// }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
/*dataBinding {
enabled = true
}*/
kapt { generateStubs = true }
buildFeatures {
dataBinding = true
viewBinding = true
}
dynamicFeatures = [":jay", ":stock", ":meddler", ':goods', ':flash', ':inventory', ':harry', ':louis', ':avery']
buildToolsVersion buildToolsVer
//kotlin DSL
/*configurations.all {
resolutionStrategy {
force("org.antlr:antlr4-runtime:4.7.1")
force("org.antlr:antlr4-tool:4.7.1")
}
}*/
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
api 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugar_ver"
api "androidx.navigation:navigation-ui-ktx:$nav_version"
api "androidx.navigation:navigation-fragment-ktx:$nav_version"
api "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
//ROOM
kapt "androidx.room:room-runtime:$room_version"
//kapt "android.arch.persistence.room:compiler:$room_version"
kapt "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
//implementation "androidx.room:room-coroutines:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
//PAGING
//implementation "androidx.paging:paging-runtime:$paging_version"
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
kapt "com.android.databinding:compiler:3.1.4"
api 'com.squareup.retrofit2:converter-gson:2.9.0'
api 'com.squareup.retrofit2:retrofit:2.9.0'
api 'com.squareup.okhttp3:logging-interceptor:4.9.0'
api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation project(path: ':avatarLib')
implementation project(path: ':ScanditCaptureCore')
implementation project(path: ':ScanditLabelCapture')
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc03"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
implementation "androidx.fragment:fragment-ktx:1.3.0-beta01"
}
更新2
如果我将依赖项从实际使用它的Dynamic Feature移动到主应用(app gradle),则应用不会启动,并且会出现以下异常:
无法启动活动
组件信息{它.kfi.智能手机/它.kfi.智能手机.ui.主要活动}:android.view.InflateException:二进制XML文件第12行:二进制XML文件第11行:膨胀类片段时出错
......我不知道该怎么办
1条答案
按热度按时间kxe2p93d1#
看起来您需要将
implementation "androidx.activity:activity-ktx:1.1.0"
添加到依赖项列表中才能工作