5

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')
....
}
Community
  • 1
  • 1
Roadblock
  • 2,041
  • 2
  • 24
  • 38

2 Answers2

1

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.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • since the configurations {...} is before the dependencies {...}, should n't that resolve the conflicts in the libraries. If I remove the configurations it throws the error mentioned here (http://stackoverflow.com/questions/27855722/top-level-exception-appdexdebug-dex-no-optimize-output-android-studio) – Roadblock Jan 09 '15 at 07:31
  • As I said in my answer, you should check and make sure you don't have the support library jar being linked in more than once. The "multiple dex files define" error is because of that. – Scott Barta Jan 09 '15 at 17:02
0

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!

Tr4X
  • 309
  • 1
  • 8