编辑-请参见底部的堆栈跟踪。
我最近为一个客户端启动了一个应用程序,第5个人进行测试后打开该应用程序便崩溃了。我要求他们发送一份崩溃报告,并且我确实有他们在做的视频。已经32个小时了,还没有崩溃报告出来。
我在google的发布前检查清单上测试过该应用的每台设备都为该应用提供了绿灯。到目前为止,是他们的Pixel XL 2在启动屏幕期间崩溃了。我无法获得一个进行测试。这是假定的崩溃的文件。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
sharedPreferences = getSharedPreferences("shared_location", MODE_MULTI_PROCESS);
editor = sharedPreferences.edit();
gpsTracker = new GPSTracker(Splash.this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
getLocationUpdates();
} else {
ActivityCompat.requestPermissions(Splash.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
ActivityCompat.requestPermissions(Splash.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
}
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
getLocationUpdates();
token = Utils.getToken(Splash.this, Constant.TOKEN);
}
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (Exception e) {
}
ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
try {
Boolean isInternetPresent = cd.isConnectingToInternet(); // true or false
if (isInternetPresent) {
RefreshData nearest = new RefreshData();
nearest.execute();
} else if(isNetworkAvailable()) {
RefreshData nearest = new RefreshData();
nearest.execute();
} else {
Common_class.Alert(Splash.this);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// Check for the integer request code originally supplied to startResolutionForResult().
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
double latitude = gpsTracker.getLatitude();
double longitude = gpsTracker.getLongitude();
strLatitude = String.valueOf(latitude);
strLongitude = String.valueOf(longitude);
editor.putString("latitude", String.valueOf(latitude));
editor.putString("longitude", String.valueOf(longitude));
editor.commit();
Intent myIntent = new Intent(this, Splash.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(myIntent);
finish();
break;
case Activity.RESULT_CANCELED:
Common_class.settingsRequest(Splash.this);
break;
}
case PERM_REQUEST_CODE_DRAW_OVERLAYS:
if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
// ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
}
}
}
break;
}
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
public void getLocationUpdates() {
if (gpsTracker.isGPSEnabled) {
double latitude = gpsTracker.getLatitude();
double longitude = gpsTracker.getLongitude();
editor.putString("latitude", String.valueOf(latitude));
editor.putString("longitude", String.valueOf(longitude));
editor.commit();
Intent service = new Intent(Splash.this, MyService.class);
startService(service);
Thread thread = new Thread(r);
thread.start();
} else {
selectAlert();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case 1:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getLocationUpdates();
token = Utils.getToken(Splash.this, Constant.TOKEN);
}
//getLocationUpdates();
break;
}
}
public void selectAlert() {
final AlertDialog.Builder builder = new AlertDialog.Builder(Splash.this);
builder.setMessage("Gps is off. Please select one of the following options.")
.setCancelable(false)
.setNegativeButton("Turn on GPS", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Common_class.settingsRequest(Splash.this);
}
})
.setPositiveButton("Select your area", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent it = new Intent(Splash.this, Select_area.class);
startActivity(it);
finish();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
public class RefreshData extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String url = "http://138.197.133.79/pocketdeal/onsplashscreen";
DefaultHttpClient client = new DefaultHttpClient();
ResponseHandler<String> handler = new BasicResponseHandler();
HttpPost post = new HttpPost(url);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("android_id", deviceId));
try {
post.setEntity(new UrlEncodedFormEntity(list));
HttpResponse httpresponse = client.execute(post);
HttpEntity resEntity = httpresponse.getEntity();
String res = httpresponse.getStatusLine().toString();
response = EntityUtils.toString(resEntity);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (s != null) {
Intent i = new Intent(Splash.this, MainActivity.class);
startActivity(i);
finish();
} else {
Intent i = new Intent(Splash.this, MainActivity.class);
startActivity(i);
finish();
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (null != activeNetworkInfo) {
if(activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI){
//we have WIFI
Log.e("Splash", "Wifi");
}
if(activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE){
//we have cellular data
Log.e("Splash", "Mobile");
}
} else{
//we have no connection :(
Log.e("Splash", "No Connection");
}
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
}
可悲的是,该代码有些丑陋且没有注释,它正在清理半未触及的文件。 有关该错误的一些猜测是.. -AsyncTask类可能会导致泄漏,但是还没有遇到任何泄漏,所以我暂时将其保留 -获取设备ID的get字符串,理想情况下这不是我应如何设置应用程序,Pixel XL 2是否可能对此进行了标记?
我会尝试修复问题,但由于无法测试,因此不确定在不投入生产之前是否正确。看看我能在各种模拟器上找到什么,并按照下面的建议换掉GPS Tracker。
编辑:从模拟器崩溃中获取了Stacktrace!
2018-11-29 18:56:39.210 6894-6928/ca.deals.pocket.pocketdeals E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: ca.deals.pocket.pocketdeals, PID: 6894
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/DefaultHttpClient;
at ca.deals.pocket.pocketdeals.ui.Splash$RefreshData.doInBackground(Splash.java:293)
at ca.deals.pocket.pocketdeals.ui.Splash$RefreshData.doInBackground(Splash.java:287)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.impl.client.DefaultHttpClient" on path: DexPathList[[zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/base.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_dependencies_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_resources_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_0_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_1_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_2_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_3_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_4_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_5_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_6_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_7_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_8_apk.apk", zip file "/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/base.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_dependencies_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_resources_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_0_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_1_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_2_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_3_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_4_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_5_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_6_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_7_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_8_apk.apk!/lib/x86, /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_slice_9_apk.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
2018-11-29 18:56:39.217 6894-6928/ca.deals.pocket.pocketdeals E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 8 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/ca.deals.pocket.pocketdeals-OfYsYiwwFsKYODoG_6dWtA==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2018-11-29 18:56:39.272 1607-1607/? E/lowmemorykiller: Error writing /proc/6894/oom_score_adj; errno=22
2018-11-29 18:56:39.437 1955-2080/system_process E/InputDispatcher: channel '2ac2a3b ca.deals.pocket.pocketdeals/ca.deals.pocket.pocketdeals.ui.Splash (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-11-29 18:56:43.068 1955-2153/system_process E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
2018-11-29 18:56:43.706 1955-1971/system_process E/memtrack: Couldn't load memtrack module
2018-11-29 18:56:43.743 1955-1971/system_process E/memtrack: Couldn't load memtrack module
我使用以下代码解决了堆栈跟踪-<uses-library android:name="org.apache.http.legacy" android:required="false"/>
现在它提出了新的问题,但这是我要解决的问题。
答案 0 :(得分:1)
通过进入adv管理器,减小像素2 xl仿真器的分配内存大小并增加其内部空间,然后重新启动Android Studio和Adv
答案 1 :(得分:0)
收到堆栈跟踪信息后,我发现解决方案是
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
针对9.0 Pie的Apache似乎是一个问题
如Gabe所说:
您正在使用一个不推荐使用的HTTP库,该库已在较新的Android设备上完全删除。将其更改为使用URLConnection
虽然Android Studio未标记此消息,但将来可能会出现