我正在開發一個Android應用程序需要消耗休息apis部署,現在,在一個heroku實例...因爲我得到崩潰隨時我嘗試集成改造爲http客戶端我已經做了以下內容:Android版應用程序與Retrofit2崩潰沒有錯誤信息
新增retrofit2爲dependendcy(沒有選擇最新的版本,以避免潛在問題的成熟)
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.google.code.gson:gson:2.6.2'
我編寫的例子Android應用程序,只是爲了檢查是否有東西在我的原始應用程序中做錯了,使用http://httpbin.org/ip
public interface HttpBinService
{
public static class Response
{
private String origin;
public Response(String origin) {
this.origin = origin;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
}
@GET("ip")
public Call<Response> getIp();
}
和主要活動
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Retrofit setup
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://httpbin.org")
.addConverterFactory(GsonConverterFactory.create())
.build();
// Service setup
HttpBinService service = retrofit.create(HttpBinService.class);
try {
Call<HttpBinService.Response> call = service.getIp();
Response<HttpBinService.Response> res = call.execute();
if (res.isSuccessful()){
Log.i("PROVARETROFIT", "OK");
((TextView)findViewById(R.id.testo)).setText(res.body().getOrigin());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
我沒有忘記我的清單
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.spich.provaretrofit">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
索要上網權限,但我的一切是該應用程序意外關閉。如果在調試中執行它,它將正確執行所有步驟直到執行調用。 LogCat似乎沒有說任何有用的東西
04-15 09:48:08.281 6491-6491/? I/art: Late-enabling -Xcheck:jni
04-15 09:48:08.367 6491-6491/? W/System: ClassLoader referenced unknown path: /data/app/it.spich.provaretrofit-1/lib/arm64
04-15 09:48:08.387 6491-6491/it.spich.provaretrofit I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
04-15 09:48:08.577 6491-6491/? I/Process: Sending signal. PID: 6491 SIG: 9
有人想到發生了什麼嗎?
刪除谷歌GSON依賴 –
你是怎麼計算/是肯定的改造正在崩潰?嘗試使用calback like services.enque(new Callback ..) – DevKRos
您是否正在使用Instant Run?如果你是,請嘗試禁用它。 –