android - Unresolved reference 包android studio

标签 android gradle kotlin android-gradle-plugin

我刚刚开始为android studio学习kotlin并建立了我的第一个项目,除了android studio之外,我什么都没有碰到,我得到了这个错误:
未解析的引用包,甚至尝试导入android.os.Bundle均无效。
起初我得到了错误:
Unresolved reference R,但是当我更新kotlin插件时,得到了我已经告诉过您的先前错误。
如我所说,我从没碰过任何东西,这些文件是由android studio本身构建的。
有任何想法吗 ?

这是应用程序级别的gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.deathstroke.samplekotlinproject"
        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"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
}

这是项目级别的gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        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()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是主要的 Activity 课:
package com.example.deathstroke.samplekotlinproject

import android.support.v7.app.AppCompatActivity
import android.os.bundle;

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: android.os.Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

android studio以红色和alt向我显示Bunlde +输入剂量没有选择作为导入类...

最佳答案

Kotlin中的类名区分大小写。因此,您必须导入Bundle而不是bundle

import android.os.Bundle

关于android - Unresolved reference 包android studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57763450/

相关文章:

android - HTTPS 网址未加密

android - Android Studio项目同步失败

Android 项目编译,但 Android Studio 无法识别 Maven 依赖项

redirect - 如何将Kotlin stdio重定向到文件?

android - 如何在 Kotlin 中比较图像文件名和字符串?

kotlin - 为什么 queryForObject Kotlin 扩展函数返回可为空的 T?如果它真的会抛出 EmptyResultDataAccessException?

android - 升级到 Android Studio 3.4,现在无法运行我的应用程序

android - Oracle 数据库移动服务器与 Couchdb

android - 通过 bundle 将 ViewPager Activity 中的值发送到 Fragment

Android 支持库 - 无法解决