简体   繁体   中英

Android Studio says “Cannot resolve symbol” when trying to access method in imported library

I'm running Android Studio 0.8.6 and imported two Firebase libraries, to use in my project.

I manage to create objects of Firebase Simple Login classes, and also default Firebase objects. However. When I try to access any method of these object, Android Studio stubbornly says "Cannot resolve symbol ".

This is my code (it's basically Firebase quick start sample code):

Firebase myRef = new Firebase("https://xxxxxxxx.firebaseIO.com/");
SimpleLogin authClient = new SimpleLogin(myRef, this);


authClient.checkAuthStatus(new SimpleLoginAuthenticatedHandler() {
    @Override
    public void authenticated(FirebaseSimpleLoginError error, FirebaseSimpleLoginUser user) {
        if (error != null) {
            // Oh no! There was an error performing the check
        } else if (user == null) {
            // No user is logged in
        } else {
            // There is a logged in user
        }
    }
});

authClient.createUser("email@example.com", "very secret", new SimpleLoginAuthenticatedHandler() {
    public void authenticated(FirebaseSimpleLoginError error, FirebaseSimpleLoginUser user) {
        if(error != null) {
            // There was an error creating this account
        }
        else {
            // We created a new user account
        }
    }
});

It is the methods '.checkOutStatus' and '.createUser' which cannot be resolved.

I've been trying every way descibed here on SO to fix it, but nothing worked out. I also attach my build.gradle file beneath:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 19
    }
}

dependencies {
    // Support Libraries
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile files('libs/firebase-simple-login-1.4.1.jar')
    compile files('libs/firebase-client-jvm-1.0.16.jar')
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Thanks in advance! :)

For resolving symbol issues, consider if your project has a settings.gradle that is NOT in the root directory, a bug in Android Studio causes it not read submodules correctly.

Here is my answer for another question that sounds similar to yours: https://stackoverflow.com/a/25224773/936067

To use the Firebase Messaging service you need to add the following dependencies to your app's build.gradle file:

            compile 'com.google.firebase:firebase-messaging:9.4.0'

All other firebase dependency files are :

dependencies {
    apply plugin: 'com.google.gms.google-services'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.firebase:firebase-client-android:2.5.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
}

I had the same problem but thanks to this answer:

https://stackoverflow.com/a/39353961/4836759

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM