Error: Cannot find character class in Android Studio

I am having serious problems building my project.

My project is building in Android Studio and the directory looks like this:

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 application and it includes projectutils as a dependency. It uses Gradle to build and I added the correct inclusions to root settings.gradle and correct dependencies for the project.

Here are my .gradle settings at 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 an error Error: (4, 34) error: package com.company.utils.database does not exist, although I added the correct dependency and Android autocomplete can see and parse the import command, so, obviously android studio can see it correctly. There are more errors, but they are all fundamentally the same: it cannot 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 built to get it going, and it's the largest brick wall ever. I have no idea what I can lose to cause these errors. I've fixed a bunch of similar bugs with Facebook and Kumulos, but this one won't work no matter what I try. Can anyone give me some pointers?

+4


source to share


5 answers


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



+3


source


Change

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

      

by



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

      

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

+1


source


I figured out the problem: I had apply plugin: 'android'

, when I should have apply plugin: 'android-library'

, I should have made a copy-paste error while editing the gradle projectutils file.

0


source


Error message: error: cannot find character class in Android Studio is linked to correct versions, for example this throws an exception:

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

      

but revisiting which version matches my latest Google Play Services update 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 compiling proyect with no problem.

0


source


I have this problem just now, the reason is that I accidentally create a class using the New → File menu item instead of New → Java Class .

I am pasting the filename without the .java extension as there is a dialog that allows me to select Java , so I don't realize my mistake at this point:enter image description here

I add the header code package

manually and everything seems to work fine (able to ctrl+ click check), but it keeps showing "cannot find symbol" for this class when trying to build.

The problem is that this method creates a filename without the .java extension .

If you get a similar error, try checking the file name extension.

0


source







All Articles