user2087530
user2087530

Reputation: 125

error: cannot find symbol class in Android Studio

I'm having major problems with building my project.

My project is getting built in Android Studio, and the directory is like so:

root
-project
--build
--libs
--src
---java
----com
-----company.project
------<All this projects source>
-projectutils
--build
--src
---main
----java
-----com.company.utils
------<All this projects source>

"project" is the main app, and it includes projectutils as a dependency. It uses Gradle to build, and I've added the correct includes to the root settings.gradle, and the correct dependencies to project.

Here is my settings.gradle in the root of my project:

include ':project', ':projectutils'

Here is my build.gradle for my project:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.company.project'
        minSdkVersion 15
        targetSdkVersion 17
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile files('libs/android-support-v4.jar')
    compile files('libs/commons-validator-1.4.0.jar')
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'joda-time:joda-time:2.3'
    compile project(':projectutils')
}

No matter what I do, it always gives the error Error:(4, 34) error: package com.company.utils.database does not exist, even though I've added the correct dependency and the Android auto-complete can see and parse the import command, so obviously Android studio is able to see it correctly. There are a ton more errors, but they are all fundamentally the same: It can't seem to find com.company.utils and I have no idea what else I need to do.

I've spent all day trying to get this thing set up just to get it running and this is the biggest brick wall so far. I have literally no idea what I could be missing to cause these errors. I've fixed a bunch of similar errors with Facebook and Kumulos but this one won't work no matter what I try. Could anyone give me some pointers?

Upvotes: 5

Views: 36582

Answers (5)

林果皞
林果皞

Reputation: 7793

I have this problem just now, the reason is because I accidentally create the class by menu item New -> File instead of New -> Java Class.

I insert file name without .java extension, since there is a dialog to allow me to choose Java, so I don't realize my mistake at this point: enter image description here

I add package header code manually, and all seems works fine (able ctrl+click to inspect), but it keep showing "cannot find symbol" for that class when trying to build.

The issue is because this method create file name without .java extension.

If you get similar error, try to check the file name extension.

Upvotes: 3

Jorgesys
Jorgesys

Reputation: 126455

The error message: error: cannot find symbol class in Android Studio is related to correct versiones installed, for example this raise the exception:

compile 'com.google.android.gms:play-services-analytics:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'

but making a review of what version correspond to my last update of Google Play Services, see this information: https://developers.google.com/android/guides/setup

i had to change :

compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'

now the proyect compile with no problem.

Upvotes: 0

Bhanu Pratap Singh
Bhanu Pratap Singh

Reputation: 1077

Change the

compile 'com.google.android.gms:play-services:6.5.87'

by

compile 'com.google.android.gms:play-services:6.1.71'

in dependencies in gradle file {build.gradle file}.

Upvotes: 2

user2087530
user2087530

Reputation: 125

I figured out the issue: I had apply plugin: 'android' when I should have had apply plugin: 'android-library' I must have made copy-paste error when editing the gradle file of projectutils.

Upvotes: 0

esme_louise
esme_louise

Reputation: 530

I usually just start restarting and rebuilding things until something "takes". If you have Android Studio start with "Sync Project with Gradle Files" (there should be an icon for it in the ribbon by default). Then try rebuilding the project. Then try closing and checking the Windows Task Manager to make sure studio64.exe has completely closed and the process has stopped running, then restart Android Studio. Also restart the device you're using for testing. That's worked for me every time I encountered an error that shouldn't be happening.

Upvotes: 3

Related Questions