Android Studio .2.2 and Gradle package does not ex

2019-06-14 22:49发布

New to Android Studio and to importing external Java libs. I have read the posts on configuring Gradle dependencies and I fixed my first package does not exist error.

These are the import statements from my MainAcitivity.java file:

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.api.client.extensions.android.http.AndroidHttp;
import om.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.tasks.TasksScopes;

and here are my dependencies statements from the build.gradle file.

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile 'com.google.android.gms:play-services:3.1.36'

I happened to stumble upon a post that specifically mentioned how to fix the import GooglePlayServicesUtil Gradle package error.

I need to add the add the other dependencies for the other 6 external imports but don't know how to find out what to name them as it is not clear to me why import com.google.android.gms.common.GooglePlayServicesUtil; maps to compile 'com.google.android.gms:play-services:3.1.36'

How do I find out what the other import to dependency mappings are for the other 6 external libs?

com.google.api.client.extensions.android.http.AndroidHttp;

com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;

com.google.api.client.http.HttpTransport;

com.google.api.client.json.JsonFactory;

com.google.api.client.json.gson.GsonFactory;

com.google.api.services.tasks.TasksScopes;

Really looking for the method on how to do this with any external imported java lib.

Thanks for your help!

2条回答
太酷不给撩
2楼-- · 2019-06-14 23:24

I had the same problem after updating all of the dependencies in my project. Originally I did have the httpClient exclusion, but it was configured differently...

configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
} 

dependencies {
    compile 'com.google.api-client:google-api-client:1.22.0'
    compile 'com.google.http-client:google-http-client-gson:1.22.0'
}

I changed it to use Nipper's example and all is well!

// removed configuration exclusion

dependencies {
    compile ('com.google.api-client:google-api-client-android:1.22.0') {
        exclude module: 'httpclient'
    }
    compile ('com.google.http-client:google-http-client-gson:1.22.0') { 
        exclude module: 'httpclient'
    }
}
查看更多
趁早两清
3楼-- · 2019-06-14 23:27

Add these dependencies:

compile ('com.google.api-client:google-api-client-android:1.17.0-rc') {
    exclude module: 'httpclient'
}
compile ('com.google.http-client:google-http-client-gson:1.17.0-rc') { 
    exclude module: 'httpclient'
}

See this example

查看更多
登录 后发表回答