次の例のアクティビティがあります。
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 をコンパイルしたところ、.jar
名前付きのunirest-java-1.4.6-SNAPSHOT-withDependency-ShadedForAndroid.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')
}
何があるかわかりません。すでにライブラリを再コンパイルしようとしましたが、変更はありませんでした。