无法导入 com.google.api.client.http。* 无法解析符号 'api'
can't import com.google.api.client.http.* Cannot resolve symbol 'api'
我不断收到错误消息 "Cannot resolve symbol 'api'."
我正在开发一个使用 Google 地点 API 跟踪用户位置的应用程序。我一直在努力让它工作,但我的导入语句一直给我带来麻烦。我在不同的地方看过,我找到的资料都告诉我不同的事情,比如...
- 将 "compile 'com.google.android.gms:play-services:9.8.0'" 放入 build.gradle。这通常会导致项目无法同步。我对此进行了一些研究,它提到了我必须如何更改 SDK,但这看起来不太乐观。
- 将 "useLibrary 'org.apache.http.legacy'" 放入 build.gradle。这有助于第一个 import 语句工作 ("import org.apache.http.client.HttpResponseException;"),但对其余部分没有帮助。
我的代码中有以下导入语句。
import org.apache.http.client.HttpResponseException;
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.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.http.json.JsonHttpParser;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
这就是 build.gradle 的样子:
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "tech.pattullo.teamzero"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.google.android.gms:play-services:9.8.0'
//compile 'com.google.android.gms:play-services:7.2.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
}
我还不确定我实际需要多少,但我不知道如何使用 'api' 符号解决该错误消息。有什么建议吗?
如果你想要 Google 个地方,你只需要这个。您不需要编译每个 Google Play 服务。
com.google.android.gms:play-services-places:9.8.0
如果您想要位置跟踪,我认为您需要位置 API,而不是地点
com.google.android.gms:play-services-location:9.8.0
我不知道您为什么需要 Apache HTTP,但这似乎与当前错误无关
我不断收到错误消息 "Cannot resolve symbol 'api'." 我正在开发一个使用 Google 地点 API 跟踪用户位置的应用程序。我一直在努力让它工作,但我的导入语句一直给我带来麻烦。我在不同的地方看过,我找到的资料都告诉我不同的事情,比如...
- 将 "compile 'com.google.android.gms:play-services:9.8.0'" 放入 build.gradle。这通常会导致项目无法同步。我对此进行了一些研究,它提到了我必须如何更改 SDK,但这看起来不太乐观。
- 将 "useLibrary 'org.apache.http.legacy'" 放入 build.gradle。这有助于第一个 import 语句工作 ("import org.apache.http.client.HttpResponseException;"),但对其余部分没有帮助。
我的代码中有以下导入语句。
import org.apache.http.client.HttpResponseException;
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.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.http.json.JsonHttpParser;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
这就是 build.gradle 的样子:
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "tech.pattullo.teamzero"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.google.android.gms:play-services:9.8.0'
//compile 'com.google.android.gms:play-services:7.2.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
}
我还不确定我实际需要多少,但我不知道如何使用 'api' 符号解决该错误消息。有什么建议吗?
如果你想要 Google 个地方,你只需要这个。您不需要编译每个 Google Play 服务。
com.google.android.gms:play-services-places:9.8.0
如果您想要位置跟踪,我认为您需要位置 API,而不是地点
com.google.android.gms:play-services-location:9.8.0
我不知道您为什么需要 Apache HTTP,但这似乎与当前错误无关