简体   繁体   中英

Android Studio not detecting support libraries on Compilation

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

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.

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.

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

Error:(17, 30) error: cannot find symbol class NotificationCompat Error:Execution failed for task ':app:compileDebugJava'.> Compilation failed; see the compiler error output for details.

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.

EDIT: I am attaching the Gradle file inside the MainProject

build.gradle in MainProject Module

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')
....
}

This part of your build file:

configurations {
all*.exclude group: 'com.android.support', module: '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'

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.

If you have jar files in a 'libs' directory, you can specify it in you build.gradle file :

dependencies{
    compile fileTree(dir: 'libs', include: ['*.jar']
    compile 'com.android.support:support-v4:21.0.3'  //to automatically add up-to-date support lib
}

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM