在Android Studio中标记为错误代码,但成功构建了gradle并在设备上运行

Ama*_*iam 10 java android android-studio

我的代码有问题.我的代码在Android Studio中标记为错误代码,但成功构建了gradle并在设备上运行,如下所示: 在此输入图像描述

当前配置:

  1. 我当前的项目在依赖项中使用了很多库.但是如果带有小库的项目不会像这样标记错误.
  2. Android Studio 1.5 RC1
  3. compileSdkVersion'Google Inc.:Google API:23
  4. buildToolsVersion '23 .0.2'
  5. classpath'com.android.tools.build:grad:1.3.1'

我做过的活动但没有解决问题:

  1. 总是清理>重建项目
  2. invalidate caches/restart>打开Android studio>打开这个项目
  3. 关闭android studio>重启电脑>再次打开android studio>打开这个项目
  4. 更新Android版本和SDK版本5.卸载Android Studio>重新安装Android Studio>打开项目

编辑:似乎错误来自android支持的每个代码,如recyclerview,CardView,APpCompact

这是我的依赖

dependencies {
    compile project(':android-crop')
    compile project(':RTEditor-Toolbar')
    compile files('libs/apache-mime4j-0.6.jar')
    compile files('libs/httpmime-4.1.3.jar')
    compile files('libs/jetbrains-annotations.jar')
    compile files('libs/gcm.jar')
    //three party library
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }
    compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
        exclude module: 'support-v4'
    }
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.vinaysshenoy:mugen:1.0.1'
    compile 'com.github.clans:fab:1.5.5'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.github.chrisbanes.photoview:library:+'
    compile 'com.subinkrishna:circularimageview:1.0.2'
    compile 'me.leolin:ShortcutBadger:1.1.3@aar'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'cn.trinea.android.common:trinea-android-common:4.2.15'
    compile 'com.sothree.slidinguppanel:library:3.1.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}
Run Code Online (Sandbox Code Playgroud)

如何解决?谢谢你的进步

小智 6

如果您的项目构建在gradle中,但是Android Studio显示错误,则Intellij缓存很可能已损坏。在某些情况下,您已经提到的菜单选项“使缓存无效/重新启动”是不够的。您可以尝试以下方法:

  1. 关机AS
  2. 手动删除缓存目录。在Windows上,该路径可能位于C:\ Users \ YOURNAME.AndroidStudio1.4 \ system \ caches之类的路径中。
  3. 重新启动AS


Ruc*_*nia 5

这是非常普遍的情况,每当我启动Android Studio时,都会发生这种情况。确保已导入代码需要导入的所有内容后,请执行以下步骤如果您不确定如何执行此操作,请查看我答案的最底端,它说可能正在发生更多问题

您可以轻松执行以下操作来修复它:

  • 清洁项目

  • 重建项目

  • 重新启动IDE

  • 更新SDK工具

这可能与您的代码无关,因此您不必为此担心。如果清理和重建不起作用,请等待一段时间。

给机器人工作室,同时成立,这可能需要几分钟的时间。通常,它甚至无需执行我上面列出的任何步骤即可自行修复。在尝试更新SDK或弄乱任何文件之前,请确保已执行此操作。如果这样做,建议您先进行备份。

我建议您看一下这个问题:

Android Studio中的“无法解析符号R”


可能会发生的更多问题

此外,根据您的屏幕截图,我在某些相同的地方看到了很多错误。这可能是因为您没有导入正确的内容!单击上面带有红色波浪线的代码段之一,然后等待消息。它应该说些关于进口的东西。然后按ALT-> ENTER。这应该导入您需要的代码才能正常工作。