【发布时间】:2018-06-21 13:00:57
【问题描述】:
示例布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<include layout="@layout/toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:padding="@dimen/spacing_xlarge"
>
</LinearLayout>
</FrameLayout>
使用下面的 gradle 构建文件,Android Studio (3.1.3) 将 ?attr/actionBarSize 标记为红色,声明它
无法解析符号
?attr/actionBarSize
使缓存失效,重启android studio没有效果,
都没有添加
implementation "com.android.support:support-v4:$support_version"
到模块 gradle 构建文件。
如何让 android studio 识别设置?
按照
的建议,我可以将android: 命名空间添加到其中
但按照我的理解,这会查找不同的属性。
build.gradle(项目)
buildscript {
ext.kotlin_version = '1.2.50'
ext.anko_version = '0.10.5'
ext.support_version = '27.1.1'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "foo.bar.App"
minSdkVersion 19
targetSdkVersion 27
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:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
implementation "com.google.code.gson:gson:2.8.1"
implementation "com.squareup.picasso:picasso:2.5.2"
}
【问题讨论】:
-
这是 Android Studio 中的错误之一。很快就会修复。即使它是红色的,您也可以毫无错误地编译您的应用程序。 reddit.com/r/androiddev/comments/8s8q7m/…
-
@Thracian 有趣的链接。自3.1以来似乎有很多问题。当我的项目实际工作时,很多东西都被标记为红色。删除 .idea 并清除缓存有助于解决其中的一些问题,但它们最终又回来了。希望 Google 能尽快解决所有这些问题并提高稳定性
-
@Eselfar 在这里也一样。获得大量“发生 IDE 错误”、未出现导入的模块和未导入绑定库等等。它很快就会得到修复。 AS 在大多数版本中都变得更好。
标签: android android-studio gradle android-gradle-plugin android-support-library