【问题标题】:Unable to resolve imports from external dependencies in Android Studio 2.0 Preview 5 + Preview 6无法在 Android Studio 2.0 Preview 5 + Preview 6 中解析来自外部依赖项的导入
【发布时间】:2016-04-26 01:51:32
【问题描述】:

从上一个 Android Studio 2.0 预览版升级到 Preview 5 后,我在从 android.support.wearable 包导入时遇到问题。

主应用和 Wear 应用的构建和运行都很好,但 Android Studio 中的编辑器抱怨它无法解析这些导入

import android.support.wearable.activity.WearableActivity;
import android.support.wearable.view.CircledImageView;
import android.support.wearable.view.WearableListView;

在 Wear 模块的 build.gradle 中,我有以下依赖项:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':common')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v13:23.1.1'

    compile 'com.google.android.support:wearable:1.3.0'
    provided 'com.google.android.wearable:wearable:1.0.0'
    compile 'com.google.android.gms:play-services-wearable:8.4.0'
}

据我了解,http://developer.android.com/training/wearables/apps/always-on.html#EnableAmbient 应该在使用 provided 语句时起作用。在 Android Studio 升级之前,它一直运行良好。我错过了什么吗?

更新:

这不仅仅是 Wear 库的问题,它似乎是任何外部依赖项的普遍问题。(主题最初是 Unable to resolve package android.support.wearable in Android Studio 2.0 预览版 5。)

这个问题似乎随时都可能发生,但实际上它主要发生在我在类中进行大量更改时(可能是对导入的更改?)。刚才它突然无法解析 Play Services 和 Facebook 广告的导入(同时还在为其他依赖项工作)。

我无意中找到了解决该问题的方法:如果我在我也安装了的 Android Studio 1.5 中打开并构建项目,则所有导入都已修复。回到 Android Studio 2.0,我可以继续编程,而不会长时间无法解析导入。

对于任何在谷歌上搜索该问题的人,Android Studio 中的错误消息是通常的无法解析符号'[package]'

【问题讨论】:

  • 所以,只是 AS 抱怨,但它构建和运行都很好?
  • 是的,尽管我已经清理了很多次项目,重新启动了 AS,在 Gradle 脚本更改后重新同步,重新启动了我的计算机等等。

标签: android android-gradle-plugin android-studio-2.0


【解决方案1】:

我在使用 AS 1.5 之前就遇到过这个问题,对我来说最简单的解决方法是使用 Android Studio 中的终端并执行:

./gradlew assembleDebug

如果您不使用风味,而不仅仅是使用风味的名称,这将起作用,例如:

./gradlew assembleFlavorNameDebug

在不离开当前 AS 实例的情况下,这也应该可以作为一种解决方法,然后如果一切设置正确,编译器就会识别您的导入。

更多参考请看:http://tools.android.com/build/gradleplugin https://stackoverflow.com/a/21307568/799162

【讨论】:

    猜你喜欢
    • 2019-03-31
    • 1970-01-01
    • 2013-12-12
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    相关资源
    最近更新 更多