【发布时间】:2019-03-20 03:19:20
【问题描述】:
问题 1: 在 MainActivity.java 中出现语法错误“无法解析符号 R”。
问题 2: 当我尝试清理或重建项目时,我收到一个很长的错误链接 here
另外值得注意的是,我仍然可以运行该应用程序并将其部署到我的手机上。只是构建应用程序的选项失败。
我尝试了一些方法,包括
正在删除 .gradle 和 .idea/libraries。
-
添加以下行
implementation 'com.android.support:support-annotations:26.1.0' 做一个项目,做一个应用
这是我的应用和 MyApp Gradle 文件。
应用级别:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "engineer.myname.myapp.myapp"
minSdkVersion 22
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-annotations:26.1.0'
implementation 'com.android.support:design:26.1.0'
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'
}
项目级别:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// 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
}
【问题讨论】:
-
我建议使用您正在使用的所有库的最新版本;支持注解 - com.android.support:support-annotations:28.0.0
-
这通常意味着,您在资源布局文件中存在 XML 问题。
-
MD Naseem Ashraf,我不知道为什么,但这确实解决了问题。老实说,我很感激和困惑。
-
如果是 XML 问题,我如何才能找到源以及为什么它会构建到我的手机中?
-
@KurtPrice 我会把我的评论变成答案,请接受它作为答案。
标签: android android-gradle-plugin build.gradle