Android Studio 内联编译器显示红色错误,但使用 gradle 编译工作正常 [英] Android Studio inline compiler showing red errors, but compilation with gradle works fine

查看:60
本文介绍了Android Studio 内联编译器显示红色错误,但使用 gradle 编译工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Android Studio 中设置了我的项目以使用 ),而且似乎旧设置从未被新设置覆盖.

修复

修复方法是从 Project Structure 屏幕中删除库依赖项,然后再次Sync Project with Gradle Files.

更多细节

您还可以通过直接打开 .idea/libraries/wire_runtime_1_2_0.xml 来查看资源使用的路径.

我坏掉的一个是:

 <组件名称="libraryTable"><库名称="wire-runtime-1.2.0"><课程><root url="jar://$PROJECT_DIR$/MY_MODULE/libs/wire-runtime-1.2.0.jar!/"/></类><JavaDOC/><来源/>

删除并重新添加库后,它将root url更改为:

 <root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.squareup.wire/wire-runtime/1.2.0/jar/44e7acbd5eb6f29698181dc3d67a60acf7efee80/wire-runtime-1.2.0.jar!/"/>

更新

Android Studio v0.4.4 显然修复了其他具有相同症状的错误,所以如果您您可能希望升级旧版本.

I've set up my project in Android Studio to use the Square Wire library, as per this question.

Build -> Compile Project works fine.

2:03:10 PM Compilation completed successfully in 31 sec

However, if I open one of my generated Protocol Buffer files, then the Square package is not being recognized.

Another symptom is that methods inherited from the Square Message class are showing as "Cannot resolve method" compile errors in the editor, even though they build and run fine.

Do I need to do something more than just adding the dependency in build.gradle for my module in my project?

解决方案

Thanks to free3dom for getting me on the right track here.

Diagnosis

The Sync Project with Gradle Files option in Android Studio seems to keep the Project Structure libraries up to date.

However, in my case there were some errors:

Expanding the (not very obvious) link showed the detail. My wire-runtime library was showing in an incorrect location:

This seemed to be a hangover from my original configuration where I had imported the JAR into a libs folder.

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

I subsequently changed it to be imported directly from Maven Central (as per here), and it seems that the old setting was never overwritten with the new one.

The Fix

The fix is to delete the library dependency from the Project Structure screen and then Sync Project with Gradle Files again.

More Detail

You can also see what path is being used to the resource by opening the .idea/libraries/wire_runtime_1_2_0.xml directly.

My broken one was:

  <component name="libraryTable">
  <library name="wire-runtime-1.2.0">
    <CLASSES>
      <root url="jar://$PROJECT_DIR$/MY_MODULE/libs/wire-runtime-1.2.0.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />

After deleting and re-adding the library it changed the root url to:

      <root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.squareup.wire/wire-runtime/1.2.0/jar/44e7acbd5eb6f29698181dc3d67a60acf7efee80/wire-runtime-1.2.0.jar!/" />

Update

Android Studio v0.4.4 apparently fixes other bugs which have the same symptoms, so if you have an older version you may wish to upgrade.

这篇关于Android Studio 内联编译器显示红色错误,但使用 gradle 编译工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆