KotlinでのAndroidプロジェクトのコンパイルが表示される未解決の参照:Rまたはコンテキスト、それ、エンティティソリューション



Android Project Compilation Kotlin Appears Unresolved Reference



1.プロジェクトでKotlinの手順を使用できるようにする方法を直接確認します。

1.アプリのbuild.gradleを追加します。



apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 28 defaultConfig { applicationId 'com.example.XXXXXX' minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName '1.0' testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout: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' implementation 'com.android.support:recyclerview-v7:28.0.0' // Edit personal information so that users can drag and arrange the order of images implementation 'com.github.SwiftyWang.android-drag-square:dragsquareimage:1.2.3' // A simple demo application, how to implement iOS Mail application like a sliding operation dependencies { compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:root@xxxxx'){ transitive=true } } // The simplest side-slip menu in history, 0 coupling, supports any ViewGroup. One step integrated sliding (delete) menu, high imitation of QQ, IOS dependencies { implementation ('com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0'){ transitive=true } } //Adapter Terminator Address: https://github.com/mcxtzhang/all-base-adapter implementation 'com.github.mcxtzhang:all-base-adapter:V1.5.2' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18' // The sliding menu library is not only used for recyclerview, but also for all views. dependencies { implementation ('com.github.anzaizai:EasySwipeMenuLayout:1.1.4'){ transitive=true } } // //Wave, water wave, Android's cool multiple water ripples MultiWaveHeader // dependencies { // implementation ('com.scwang.wave:MultiWaveHeader:1.0.0-alpha-3'){ // transitive=true // } // } //androidx // implementation 'com.scwang.wave:MultiWaveHeader:1.0.0-andx-3' implementation 'org.adw.library:discrete-seekbar:1.0.0' // Particle animation implementation 'me.wangyuwei:ParticleView:1.0.4' //Pull down to refresh and pull up to load the frame implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-21' //Round picture avatar frame implementation 'de.hdodenhof:circleimageview:2.0.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion' implementation'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:support-v4:28.0.0' //Used to check the life cycle of Activity without having to rely on Activity implementation 'android.arch.lifecycle:viewmodel:$lifecycle_runtime_version' implementation 'android.arch.lifecycle:livedata-core:$lifecycle_runtime_version' implementation 'android.arch.lifecycle:extensions:$lifecycle_runtime_version' }

ご覧のとおり、次を追加する必要があります。

apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion' implementation'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version'

2.プロジェクトのbuild.gradleを追加します。



// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { // ext.kotlin_version = '1.3.50' ext.kotlin_version = '1.2.30' ext.coroutinesVersion = '1.2.2' ext.lifecycle_runtime_version = '1.1.0' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version' // NOTE: Do not place your application dependencies here they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir }

ご覧のとおり、次を追加します。

classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version'

2.問題解決:



Kotlinのバージョン番号が一貫しているかどうかを確認します。一貫性がない場合は、エラーが報告されます。一貫性のあるものに変更するだけ

次のこともできます:ファイル->キャッシュの無効化/再起動。再起動後、[ビルド]-> [プロジェクトの再ビルド]を選択します。