【发布时间】:2018-09-10 19:04:45
【问题描述】:
在我的项目中,通过 USB 将其从一台 PC 移动到另一台后,我开始在几乎每一行的每个文件中都出现错误,但该应用程序仍然可以在模拟器上构建和运行。
据我所知,android studio 无法找到 support-v7 库来导入所有文件
这是我的主要活动:
import android.support.design.widget.NavigationView
import android.support.design.widget.Snackbar
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
我得到的错误信息是:
未解决的参考:小部件
这是我的项目级 gradle 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的应用程序 gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.test"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-messaging:17.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.github.bumptech.glide:volley-integration:4.8.0'
implementation 'com.github.d-max:spots-dialog:1.1@aar'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'android.arch.paging:runtime:1.0.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android-extensions'
您还可以从这张图片 中看到 intelli sens 正在引发各种错误,但如果我运行它,它将启动并在模拟器或我的设备上完美运行。
这是来自运行 gradle 同步:
到目前为止我所尝试的:
- 通过更改应用版本代码重新同步 gradle
- 构建 -> 清理项目
- 构建 -> 重建项目
- 文件 -> 使缓存无效/重新启动
- 文件 -> 将项目与 gradle 文件同步
【问题讨论】:
-
为什么你的应用 gradle 文件中有 2 个
apply plugin: 'kotlin-android-extensions'?请删除一个并重新检查。 -
试过了,同样的问题
-
导入您的项目。不要从最近的项目和打开的项目中打开。
-
谢谢@Naveen,这解决了我的问题。如果你愿意,你可以将它作为答案发布,我会接受它