5

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?

user2087530
  • 125
  • 1
  • 1
  • 10

5 Answers5

3

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.

esme_louise
  • 540
  • 2
  • 9
  • 28
  • Didn't work. I'm convinced there is something wrong with either my Gradle files or my dependency setup through Android Studio, but both the other dependecnies - Facebook and kumulos, have been setup exactly the same way, yet they work and utils doesn't. – user2087530 Aug 15 '14 at 19:35
  • Yes, now that I look at it again, I agree. You may find this post helpful: http://stackoverflow.com/questions/17323858/using-gradle-with-an-existing-android-project – esme_louise Aug 15 '14 at 19:55
3

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.

林果皞
  • 7,539
  • 3
  • 55
  • 70
2

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

Bhanu Pratap Singh
  • 1,017
  • 1
  • 12
  • 15
  • In my case it was: implementation 'com.google.android.gms:play-services-auth:20.1.0' -> implementation 'com.google.android.gms:play-services-auth:20.4.0' – Maxim Jan 08 '23 at 13:56
0

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.

user2087530
  • 125
  • 1
  • 1
  • 10
0

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.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268