Android studio提示找不到在项目中已经引入的部分依赖

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010144805/article/details/82013290

问题描述:

Android studio提示找不到在项目中已经引入的部分依赖,但是硬打包运行也可以成功。

以MultiDex为例:

import android.support.multidex.MultiDex;//红字提示:Cannot resolve symbol 'MultiDex'

项目的.iml文件中能找到:

< orderEntry type="library" exported="" name="Gradle: com.android.support:multidex-1.0.1" level="project" />
< orderEntry type="library" exported="" scope="TEST" name="Gradle: com.android.support:multidex-instrumentation-1.0.1" level="project" />

$PROJECT_DIR$/.idea/libraries目录中找到Gradle__com_android_support_multidex_1_0_1.xml

<component name="libraryTable">
  <library name="Gradle: com.android.support:multidex-1.0.1">
<CLASSES>
  <root url="jar://$PROJECT_DIR$/[module_name]/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/jars/classes.jar!/" />
  <root url="file://$PROJECT_DIR$/[module_name]/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
  </library>
</component>

检查项目目录,发现[module_name]/build/intermediates/exploded-aar/目录不存在。

解决办法:

可以配置项目目录下的gradle.properties ,添加:

#停用BuildCache功能
android.enableBuildCache=false

然后重建项目即可在 [module_name]/build/intermediates/看到exploded-aar目录,import依赖也不再报错。

这是AS的BuildCache功能,即使用C:\Users\[user_name]\.android\build-cache目录下的缓存文件来代替exploded-aar,不过AS编译时又不识别了,简直是大水冲了龙王庙。删除该行或置为true即可重启该功能。

网上又搜了一遍,发现exploded-aar目录问题主要发生在Android Studio 2.3,Gradle Plugin 2.3.0(对应推荐使用 Gradle 3.3),已经在gradle plugin 2.5 版本修复好了。

Marked as Fixed

in 2.3/2.4 you can look in the build cache entries and look in the input file that indicate the source of the cache entry (maven coordinate).
in 2.5+ we switched to Gradle’s own cache so you’ll have to look in the gradle folder.
If all you need is manually get the aar content you could also manually download the aar and unzip it yourself.

查看 Issue 详情(需要梯子):Issue 页

猜你喜欢

转载自blog.csdn.net/u010144805/article/details/82013290