user3342330
user3342330

Reputation:

package com.google.common.collect does not exist

Using Android studio -.5.1.

When editing my class with the following import statements no errors show and I can use all the auto complete function of the editor.

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

But when I actually try to run I get the following.

Error:(3, 33) error: package com.google.common.collect does not exist

Obviously my set up is wrong somewhere but I have no idea where to look. There are dozens of similar questions but nothing seems to be explicit enough to enable me to correct the problem.

Build errors:

Information:Gradle tasks [:app:assembleDebug]
Information:11 errors
Information:12 errors
Information:0 warnings
Information:See complete output in console
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
C:\Program Files\Android Studio\MultiLevelList\app\src\main\java\com\multilevellist\StockMatrix.java
Error:(3, 33) error: package com.google.common.collect does not exist
Error:(4, 33) error: package com.google.common.collect does not exist
Error:(7, 13) error: cannot find symbol class Multimap
Error:(7, 31) error: cannot find symbol class Multimap
Error:(8, 13) error: cannot find symbol class Multimap
Error:(8, 31) error: cannot find symbol class Multimap
Error:(9, 13) error: cannot find symbol class Multimap
Error:(7, 70) error: cannot find symbol variable ArrayListMultimap
Error:(8, 70) error: cannot find symbol variable ArrayListMultimap
Error:(25, 14) error: cannot find symbol class Multimap
Error:(26, 36) error: cannot find symbol class Multimap

build.gradle:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Upvotes: 5

Views: 27232

Answers (3)

akiraspeirs
akiraspeirs

Reputation: 2135

I had a related problem with builds on Jenkins. The app would compile in Android Studio but not on my build machine.

This was due to an unused Guava import statement in my .java file. I no longer used Guava code in my app so I removed it from build.gradle, but accidentally left the import statement in code.

Android Studio compiled even with the import statement remaining there, but my build machine would fail.

Removing the import statement fixed this.

Upvotes: 0

Suman Mahto
Suman Mahto

Reputation: 61

Try with this one

dependencies{
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.google.guava:guava:16+"
}

Upvotes: 6

Scott Barta
Scott Barta

Reputation: 80020

It looks like you're trying to use the Guava library, but you haven't added it in a way that's making it to the correct build files; this is probably a bug in Android Studio, and if you give me more details on how you got there, I can make sure there's a bug filed against it.

The easy way to add common libraries is Project Structrue > Modules > (your module) > Dependencies > + button > Library dependency

Guava will be in the list of common dependencies:

Screen shot of dependencies, showing Guava

Upvotes: 11

Related Questions