我有以下示例活动:
package teste.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView) findViewById(R.id.mainText);
try {
text.setText(Unirest.get("http://google.com").asString().getBody());
}catch (UnirestException e){
throw new RuntimeException(e);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}我从官方指南后面的源代码编译了Unirest,最后得到了一个名为unirest-java-1.4.6-SNAPSHOT-withDependency-ShadedForAndroid.jar的.jar。
当我运行该活动时,它会立即与标题上的错误中断。下面是完整的堆栈跟踪(带有错误筛选器的logcat):
04-03 10:50:55.150 1767-1767/teste.myapplication E/dalvikvm﹕ Could not find class 'javax.naming.ldap.LdapName', referenced from method com.mashape.relocation.conn.ssl.AbstractVerifier.extractCNs
04-03 10:50:55.170 1767-1767/teste.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: teste.myapplication, PID: 1767
java.lang.VerifyError: com/mashape/relocation/conn/ssl/AbstractVerifier
at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:126)
at com.mashape.relocation.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:98)
at com.mashape.relocation.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:105)
at com.mashape.unirest.http.options.Options.refresh(Options.java:73)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:46)
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:134)
at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
at teste.myapplication.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "teste.myapplication"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
compile files('libs/unirest-java-1.4.6-SNAPSHOT-withDependency-ShadedForAndroid.jar')
}我不知道会是什么。我已经试过重新编译图书馆了,但没有什么变化。
发布于 2015-04-14 00:34:49
最后,我使用了改造,它工作起来很有魅力。
最后,在运行API 21的AVD中,错误消失了(我以前在AVD运行API 19上测试,我的手机也在19上),也许更新是关键,但是如果您的应用程序目标是API 19和更低版本,而且您不能更改库,那么我就不知道了。
发布于 2015-04-12 19:43:37
在您的android设备上,转到“设置”、“关于软件”、“系统更新”、“更新”。
https://stackoverflow.com/questions/29434271
复制相似问题