import com.google.android.gms.common.api.GoogleApiClient; cannot be resolved - android

I want to make a login with Google+ login button like this Tutorial
I have copied the codes, set google_play_services libraries, added package name and SHA1 key in google api console, but there are some import errors :
This import is not an error :
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.plus.model.people.Person;
But this import an error (cannot be resolved) :
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.plus.Plus;
Anybody have a solution ?

Add this in yourbuild.gradle(app) inside dependency
compile 'com.google.android.gms:play-services:8.1.0'

[Solved]
I try to download new version of google-play-services library and import error is gone.
So, always update/download newest version of google-play-services library..

You need to add the dependency to your app.
Instructions for eclipse here
http://developer.android.com/google/play-services/setup.html
You can also do this by right clicking on your app (if you're using Android Studio) selecting Open Module Settings, going to the dependency tab. Then Clicking the "plus" at the lower left, select library dependency, then find play-services

Related

android : navigation drawer and upgrading libraries methodology

Im following headfirst methodology to learn to code in androidstudio.
they provide some code for building a simple navigation drawer app.
in order to be compatible with previous android version, they advise to import :
import android.content.Intent;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
but in my last version of android studio this doesnt work : some of them are greyed and alt+enter does not import the correct library when i put the java code provided by my methodology.
so i replaced a few imports with the newer versions. for example :
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBarDrawerToggle ;
import android.widget.Toolbar;
however, i did not find anything for to import "NavigationView" and com.google.android.material.navigation.NavigationV iew is grayed when i try to import it.
So my question is basic: how do i know which lib to import when android studio does not suggest anything with alt+enter and when the libraries have evolved? the question could be asked for many programs i guess ..is there a standard methodology to upgrade the code?
You first need to include your dependencies in your build.gradle (app) file.
For example, your NavigationView is a part of Google's Material library. This library does not come included in Android SDK when you create the project and therefore you need to add the library under 'dependencies' in your build.gradle (app) file in order to use it:
dependencies {
implementation 'com.google.android.material:material:1.3.0-alpha01'
}
This way, upon the build of the project, Gradle will download the library and include it in your project so you can use the Material components. You can usually find the gradle dependency you need to include with a quick Google search.
Another thing to note is that the legacy support libraries have been replaced with AndroidX as you can read here:
https://developer.android.com/topic/libraries/support-library
https://developer.android.com/jetpack/androidx
And you can find the full list of AndroidX support libraries in here:
https://developer.android.com/jetpack/androidx/explorer

What is the correct library for Firebase's addValueEventListener?

I'm using multiple different imports with Firebase:
import com.firebase.client.Firebase;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.ValueEventListener;
however, when I try to do
query.addValueEventListener
It doesn't recognize addValueEventListener. I've tried remaking the project and invalidating caches and restarting, but I'm still getting this error. What could possibly be wrong?
The appearance of this:
import com.firebase.client.Firebase;
indicates you are including the legacy Firebase SDK along with the "new" SDK. Not a good practice. Best to update your build.gradle dependencies to eliminate:
compile 'com.firebase:firebase-client-android:2.x.x'
If there are places in your code where you are using the legacy API, you can use the hints in the Upgrade Guide to migrate to the new API.
This should also resolve your other recent question.

android BaseGamesUtils library error

I'm trying to implement the google play services in my app. I have successfully imported BaseGameUtils library from GitHub, referenced the GooglePlayServicesLib to the library, but it has a really annoying error...
This is part of the GameHelper.java file :
import com.google.android.gms.appstate.AppStateManager;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.google.android.gms.games.multiplayer.Invitation;
import com.google.android.gms.games.multiplayer.Multiplayer;
import com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatch;
import com.google.android.gms.games.request.GameRequest;
import com.google.android.gms.plus.Plus;
Everything is OK except the import com.google.android.gms.games.request.GameRequest; line which is underlined with the error message : com.google.android.gms.games.request cannot be resolved
I have no idea about how to solve this problem, and I see that the help community around google play games services is not as large as I would have bet...
any help would be welcome ! :)
I ran into the same problem. What fixed it for me was updating the google play-services library to a newer version.
Update the google play services library to the latest version. Thanks

FragmentTransaction in support-v4 does not have detach()?

I've been looking far and wide for solutions to this but alas in my sample project I still get the following errors
"The method isDetached() is undefined for the type Fragment"
"The method detach(Fragment) is undefined for the type FragmentTransaction"
What is the matter here? I have the following imports
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
And I use SDK version 8
<uses-sdk android:minSdkVersion="8" />
Make sure that the jar file you're importing is the most recent one. There are a few android-support-v4.jar files and I've caught a few differences in the APIs they implement.
Download it again and make sure that you import the most recent file in eclipse.

google-api-java-client library not working in android

I am trying to use Google's places API. I downloaded google-api-java-client-1.6.0-beta.zip library and I'm using source code from https://github.com/tuthan/Google-Place-Api-Demo
I import the external library in exactly the correct way, but the code still give me compile time errors on all imports of google-api-java-client-1.6.0-beta.zip.
e.g.
import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.http.json.JsonHttpParser;
import com.google.api.client.json.jackson.JacksonFactory;
I've been working on this for a week, but have been unable to solve it.
The dependency jars are not in your classpath. Please add the jar from google-api-java-client-1.6.0-beta.zip to your sample project.

Categories

Resources