Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 252
user2087530 Avatar asked Aug 15 '14 18:08

user2087530


3 Answers

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.

like image 174
esme_louise Avatar answered Oct 31 '22 00:10

esme_louise


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.

like image 40
林果皞 Avatar answered Oct 30 '22 22:10

林果皞


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

like image 36
Bhanu Pratap Singh Avatar answered Oct 30 '22 22:10

Bhanu Pratap Singh