Unable to import Google client after updating Android Studio

After upgrading to Android Studio 2.3, it appears that I cannot use the code for Cloud Endpoints

class EndpointsAsyncTask extends AsyncTask<Pair<Context, String>, Void, String> { private static MyApi myApiService = null; private Context context; @Override protected String doInBackground(Pair<Context, String>... params) { if(myApiService == null) { // Only do this once MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null) // options for running against local devappserver // - 10.0.2.2 is localhost IP address in Android emulator // - turn off compression when running against local devappserver .setRootUrl("http://10.0.2.2:8080/_ah/api/") .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { @Override public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException { abstractGoogleClientRequest.setDisableGZipContent(true); } }); // end options for devappserver myApiService = builder.build(); } context = params[0].first; String name = params[0].second; try { return myApiService.sayHi(name).execute().getData(); } catch (IOException e) { return e.getMessage(); } } @Override protected void onPostExecute(String result) { Toast.makeText(context, result, Toast.LENGTH_LONG).show(); } } 

The problem occurs when importing AndroidHttp and AndroidJsonFactory. It worked with click-alt-enter import, not now. I can copy the import manually

 import com.google.api.client.extensions.android.http.AndroidHttp; import com.google.api.client.extensions.android.json.AndroidJsonFactory; import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; import com.google.api.client.googleapis.services.GoogleClientRequestInitializer; 

but it highlights the "client", cannot allow the work with the character client. The gradle file has a dependency compilation project (path: ': backend', configuration: “Android endpoints”), and I'm in sync.

Instead of trying to roll back the versions, is there another import that we need to use now or configure differently? Is Google Cloud Page Code Obsolete?

+7
google-cloud-endpoints
source share
2 answers

I added these dependencies to the build.gradle file of the endpoints:

 compile group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0' compile group: 'com.google.api-client', name: 'google-api-client-android', version: '1.22.0' 

I don’t know why they are needed, but I solved it by adding these dependencies to the missing packages.

+12
source share

The best solution I can find is here where it says

HttpClient is no longer supported in sdk 23. You must use URLConnection or downgrade for sdk 22

also

Google officially offers developers to use the Volley library to create related materials here ,

0
source share

All Articles