Android Studio 在编译时未检测到支持库

问题描述:

由于 Android Studio 将成为 Android 开发的默认 IDE,我决定将我现有的项目迁移到 Android-studio.项目结构似乎不同,我的项目中文件夹的层次结构如下:

Since Android Studio is going to be default IDE for Android Development, I decided to migrate my existing project into Android-studio. The project stucture seems different and the hierarchy of folders in my Project is as follows:

Complete Project
 ->.idea
 -> build
 -> Facebook SDK
 -> MainProject
 -> ... (Other Libraries)
 build.gradle
 local.properties
 settings.gradle
 ...
External Libraries
 -> Android API 8 Platform
 -> Android API 18 Platform
 -> Android API 19 Platform
 -> 1.7 Java
 -> support-v4-19.1.0

我的 MainProject 有一个 libs 文件夹,其中包含项目中使用的不同 jar.令人惊讶的是,它不包含我的 eclipse 项目中存在的 android-support-v4 jar.所以,看来根目录下的外部Libraries文件夹必须要处理一下.

My MainProject has a libs folder which contains different jars used within the project. It surprisingly does not contain the android-support-v4 jar which was present in my eclipse project. So, it seems that the external Libraries folder at the root must take care of it.

但导入后,当我尝试编译项目时开始抛出找不到符号错误";对于某些与 android 支持库相关的类.

But after import, when I tried to compile the project started throwing "Symbol not found error" for Certain Classes all relating to android support library.

例如:Android Studio 中的自动完成功能为我提供了来自 android.support.v4.app.NotificationCompat 的 NotificaitonCompat 建议,但是当我尝试编译我的项目模块时,它说

For Eg: The auto complete in Android Studio gives me suggestion for NotificaitonCompat from android.support.v4.app.NotificationCompat, but when I try to compile my Project Module it says

错误:(17, 30) 错误:找不到符号类 NotificationCompat 错误:任务:app:compileDebugJava"的执行失败.>编译失败;有关详细信息,请参阅编译器错误输出.

对于同一个支持库,这也发生在许多其他类中.我尝试插入一个 jar 并在 MainProject 的 build.gradle 中更改相同的内容,但错误仍然存​​在.

This happens in many other classes too for the same support library. I tried to insert a jar and changed the same in the build.gradle for the MainProject, but the error persists.

我什至尝试重新启动并再次构建项目,但没有任何改变.

I even tried restarting and building the project again, but nothing changed.

我在 MainProject 中附加 Gradle 文件

I am attaching the Gradle file inside the MainProject

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "package.app"
    minSdkVersion 8
    targetSdkVersion 19
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}

dependencies {
compile project(':facebookSDK')
compile project(':library')
compile project(':volley')
compile 'com.google.android.gms:play-services:+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/FlurryAnalytics_3.3.3.jar')
compile files('libs/universal-image-loader-1.8.4.jar')
....
}

构建文件的这一部分:

configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}

告诉构建系统忽略 support-v4,这就是它不编译的原因.删除那个.

is telling the build system to ignore support-v4, which is why it isn't compiling. Remove that.

在你的构建文件中,你有这个,这是包含支持的正确方法:

In your build file, you have this, which is the correct way to include support:

compile 'com.android.support:support-v4:19.1.0'

如果您在任何模块的 libs 目录中有支持库 jar 文件,请将其删除并确保以这种方式引用它 -- 如果您将库作为 jar 包含在内,您可能会遇到多次包含 jar 的问题,这将导致 dex 错误.

If you have the support library jar file in the libs directory of any of your modules, remove it and make sure you refer to it this way -- if you include the library as a jar, you're likely to run into a problem where the jar is included multiple times which will result in a dex error.