当我使用Android Studio 3.1构建Android P的应用程序时,我遇到了这样的错误,可以制作apk,但是当我在Android P模拟器上使用它时,它会崩溃并抛出以下信息,更多细节请参见图片.
java.lang.NoClassDefFoundError:解析失败:Lorg/apache/http/ProtocolVersion

App模块下的build.gradle的一部分在下面,有人见过这个吗?并给出一些建议?非常感谢.
android {
compileSdkVersion 'android-P'
buildToolsVersion '28-rc1'
useLibrary 'org.apache.http.legacy'
//for Lambda
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 17
targetSdkVersion 27
versionCode xxxx
versionName "Vx.x.x"
multiDexEnabled true
//other setting required
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a', 'x86', 'x86_64', 'mips', 'mips64'
}
Run Code Online (Sandbox Code Playgroud) android google-maps gradle apache-httpcomponents android-9.0-pie
我要做的就是下载一些JSON并将其反序列化为一个对象.我还没有下载JSON.
我能找到的几乎所有HttpClient示例,包括apache站点上的那些看起来都像......
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
public void blah() {
HttpClient client = new DefaultHttpClient();
...
}
Run Code Online (Sandbox Code Playgroud)
但是,Netbeans告诉我,这DefaultHttpClient已被弃用.我已经尝试使用谷歌搜索DefaultHttpClient deprecated和其他许多变化,我无法找到任何有用的结果,所以我显然错过了一些东西.
下载网页内容的正确Java7方式是什么?作为语言的一部分,真的没有像样的Http客户端吗?我觉得很难相信.
我对Maven的依赖是......
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>LATEST</version>
<type>jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud) 在Android M上,Google完全取消了对Apache HTTP客户端的支持.
这可能也是Android M上如此多应用程序崩溃的原因.
来自Google Dev资源:
此预览删除了对Apache HTTP客户端的支持.如果您的应用使用此客户端并定位到Android 2.3(API级别9)或更高版本,请改用HttpURLConnection类.此API更高效,因为它通过透明压缩和响应缓存减少了网络使用,并最大限度地降低了功耗.要继续使用Apache HTTP API,必须首先在build.gradle文件中声明以下编译时依赖项:
Run Code Online (Sandbox Code Playgroud)android { useLibrary 'org.apache.http.legacy' }Android正在从OpenSSL转向BoringSSL库.如果您在应用程序中使用Android NDK,请不要链接不属于NDK API的加密库,例如libcrypto.so和libssl.so.这些库不是公共API,可能会在不同版本和设备之间发生更改或中断,恕不另行通知.此外,您可能会暴露自己的安全漏洞.相反,修改您的本机代码以通过JNI调用Java加密API或静态链接到您选择的加密库.
我正在使用Eclipse而我没有Gradle,是否有任何解决方法?
我真的需要很快更新应用程序,但我能不端口Android Studio现在
更新到Android Studio 2.3后,似乎我无法使用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's 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<?> …Run Code Online (Sandbox Code Playgroud)