我今天将Android Studio升级到3.1,现在Android Studio说它无法解析大多数资源的符号(例如ThemeOverlayin styles.xml或?attr/actionBarSize).到目前为止,这似乎并没有阻止我在模拟器中构建或运行,但这些错误让我感到紧张.
还有其他人遇到过这个问题吗?我怎样才能解决它?我尝试过同步gradle和清理我的项目,但它似乎没有任何帮助.
有任何想法吗?
我正在使用带有Gradle版本4.4和Gradle Plugin 3.1.0的Android Studio 3.1
编辑: 此问题影响更新到Android Studio 3.1.1,3.1.2,3.1.3,3.1.4以及Gradle Plugin到3.1.1,3.1.2,3.1.3和3.1.4.但是,下面的答案仍然有效.
android intellij-idea android-resources android-studio android-studio-3.1
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/card_outer_padding"
android:layout_marginTop="@dimen/card_outer_padding"
android:layout_marginRight="@dimen/card_outer_padding"
android:layout_marginBottom='@{model.cardBottomMargin}'
android:foreground="?attr/selectableItemBackground"
android:onClick="@{model::onCardClick}"
app:cardElevation="2dp"
app:cardCornerRadius="2dp"
app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息
无法解析符号?attr/selectableItemBackground
验证Android XML文件中的资源引用.
<TextView
android:id="@+id/country_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:text="@{model.name}"
style="@style/TextAppearance.AppCompat.Headline"
tools:text="Country"/>
Run Code Online (Sandbox Code Playgroud)
而且,我也遇到了类似的错误
无法解析符号'@ style/TextAppearance.AppCompat.Headline'
验证Android XML文件中的资源引用.
任何指针都会很棒!谢谢!它似乎与此线程有关,但没有提供解决方案:
Theme.AppCompat.Light.DarkActionBar未在styles.xml中进行编译.我compile 'com.android.support:appcompat-v7:25.1.0'在app模块中添加了
build.gradle.
我在谷歌搜索了解决方案.其中很多是关于更改Project的类路径.build.gradle但它显示相同的错误.
build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-annotations:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
// compile 'ch.acra:acra:4.5.0'
testCompile 'junit:junit:4.12'
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode = 146
versionName = "0.6.65"
}
Run Code Online (Sandbox Code Playgroud) 正如style.xml中所述,有一个奇怪的错误,它显示无法解析符号'Theme',这很奇怪.
我的项目规格: -
使用Android Studio 3.0
和gradle版本3.0.0
和distributionUrl = https://services.gradle.org/distributions/gradle-4.1-all.zip
编辑:-
尝试通过转到文件>无效缓存/重新启动>无效和重新启动来清除缓存,但无效,因为错误仍然存在.
我将我的android studio更新到最新版本 - 3.0.1.从那以后,它在以下代码行中为Theme和ThemeOverlay抱怨'无法解析符号'.应用程序运行正常但它们在文件中以红色标记.
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
build.gradle使用最新版本进行更新
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
Run Code Online (Sandbox Code Playgroud) 昨晚,我将我的android工作室从3.0.1升级到3.1,并重建我的项目,我得到了如下所示的错误.
检查清单:
compileSdkVersion 27
buildToolsVersion '27 .0.3'
classpath'com.android.tools.build:grad:3.10'
实现'com.android.support:appcompat-v7:27.1.0'
实现'com.android.support:design:27.1.0'
我的项目构建和运行顺利,但是在styles.xml中,"Theme"以红色突出显示,每次我将项目提交给Git时都会注意到这个错误:
Error:(4, 36) Cannot resolve symbol 'Theme'
styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
请注意,我已尝试将我的项目与gradle文件同步,并确保google()在我的buildscript块中存在,build.gradle如下面这些问题的答案中所述:
2] 无法在styles.xml(Android Studio)中解析符号'Theme'
这些问题中接受/最高投票的答案并没有解决我的问题,请帮忙