【发布时间】:2020-01-05 21:00:03
【问题描述】:
我刚开始为 android studio 学习 kotlin 并构建了我的第一个项目,除了 android studio 给我这个错误之外,我什么都没碰: 未解析的参考包,即使尝试导入 android.os.Bundle 也没有用。 起初我得到了错误: 未解决的参考 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
}
这是主要的活动类:
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 向我展示了红色的 Bunlde,而 alt + Enter 没有作为导入类的选项...
【问题讨论】:
标签: android gradle kotlin android-gradle-plugin