gpt4 book ai didi

android - kotlinx.android.synthetic 未使用的 android studio 问题

转载 作者:IT老高 更新时间:2023-10-28 13:30:18 34 4
gpt4 key购买 nike

我正在使用 kotlin + Rxjava + MVVM 开展一个项目。在开发过程中面临在 Fragment 或 viewholder 中导入 View id 的问题。

import kotlinx.android.synthetic.main.layout.* 未用于 kotlin。

kotling synthetic imports is unused

通常 View id 应该从 kotlin 合成布局导入中使用,但它直接从 R.id 导入它不应该发生。

Kotlin 插件版本:org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.40

我的 gradle 文件:

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'idea'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 27
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}


lintOptions {
abortOnError false
}
}

dependencies {

api "com.android.support:design:$rootProject.support_library_version"
api "com.android.support:appcompat-v7:$rootProject.support_library_version"
api "com.android.support:recyclerview-v7:$rootProject.support_library_version"
api "com.android.support:support-dynamic-animation:$rootProject.support_library_version"
api "com.android.support:cardview-v7:$rootProject.support_library_version"
api "com.android.support:customtabs:$rootProject.support_library_version"

api "com.android.support.constraint:constraint-layout:1.1.0-beta5"
api 'android.arch.lifecycle:extensions:1.1.0'


api 'androidx.core:core-ktx:0.2'


api "com.google.dagger:dagger:$rootProject.dagger_version"
kapt "com.google.dagger:dagger-compiler:$rootProject.dagger_version"

api "android.arch.persistence.room:runtime:$rootProject.room_version"
kapt "android.arch.persistence.room:compiler:$rootProject.room_version"
testImplementation "android.arch.persistence.room:testing:$rootProject.room_version"
api "android.arch.persistence.room:rxjava2:$rootProject.room_version"
androidTestImplementation "android.arch.core:core-testing:$rootProject.room_version"
testImplementation "android.arch.core:core-testing:$rootProject.room_version"

api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"


api 'com.jakewharton.timber:timber:4.5.1'

api "com.android.support:multidex:1.0.3"

api "com.github.bumptech.glide:glide:$rootProject.glide_version"
api "jp.wasabeef:glide-transformations:$rootProject.glide_transformation_version"
api 'com.github.bumptech.glide:okhttp3-integration:1.5.0@aar'

api "io.reactivex.rxjava2:rxandroid:$rootProject.rxAndroid_version"
api "io.reactivex.rxjava2:rxjava:$rootProject.rxJava_version"
api "com.google.code.gson:gson:$rootProject.gson_version"

api("com.squareup.retrofit2:retrofit:$rootProject.retrofit_version") {
// exclude Retrofit’s OkHttp peer-dependency module and define your own module import
exclude module: 'okhttp'
}

api "com.squareup.okhttp3:okhttp:$rootProject.okhttp_version"
api "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttp_version"
api "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofit_version"
api "com.squareup.retrofit2:converter-gson:$rootProject.retrofit_version"

api 'com.jakewharton.threetenabp:threetenabp:1.0.5'

api "com.google.firebase:firebase-invites:$rootProject.play_services_version"
api "com.google.firebase:firebase-core:$rootProject.play_services_version"
api "com.google.firebase:firebase-config:$rootProject.play_services_version"
api "com.google.firebase:firebase-perf:$rootProject.play_services_version"
api "com.google.firebase:firebase-auth:$rootProject.play_services_version"
api "com.google.firebase:firebase-firestore:$rootProject.play_services_version"



api("com.firebaseui:firebase-ui-auth:$rootProject.firebase_ui_version") {
// exclude Retrofit’s OkHttp peer-dependency module and define your own module import
exclude module: 'play-services-auth'
exclude module: 'firebase-auth'
}

// Required only if Facebook login support is required
api('com.facebook.android:facebook-android-sdk:4.31.0')

api "com.google.android.gms:play-services-auth:$rootProject.play_services_version"

// Required only if Twitter login support is required
api("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true }

api 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0'
api 'com.jakewharton.rxbinding2:rxbinding-support-v4-kotlin:2.0.0'
api 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7-kotlin:2.0.0'
api 'com.jakewharton.rxbinding2:rxbinding-design-kotlin:2.0.0'

api('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
}

我也尝试过干净的构建和重建项目。

知道如何解决这个问题吗?

最佳答案

我尝试了几种方法,包括此线程中报告的解决方案。我还发现很多人都面临着这个烦人的问题,如您所见 here

尽管如此,到目前为止对我有用的最接近这个问题的解决方案是从 gradle、Sync gradle 插件中删除 apply plugin: kotlin-android-extensions 和然后重新添加。

关于android - kotlinx.android.synthetic 未使用的 android studio 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50015465/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com