Android 为什么这段代码只在9.0上崩溃?
编辑-请参见底部的堆栈跟踪 我最近为一个客户发布了一个应用程序,第五个测试者在打开应用程序后立即崩溃。我要求他们发送一份坠机报告,我确实有他们这样做的视频。已经32个小时了,还没有收到坠机报告 我测试过的每一款设备,加上谷歌发布前的检查清单,都为这款应用亮起了绿灯。到目前为止,是他们的像素XL 2在启动屏幕时崩溃。我无法获得一个测试。这里是假定崩溃的文件Android 为什么这段代码只在9.0上崩溃?,android,Android,编辑-请参见底部的堆栈跟踪 我最近为一个客户发布了一个应用程序,第五个测试者在打开应用程序后立即崩溃。我要求他们发送一份坠机报告,我确实有他们这样做的视频。已经32个小时了,还没有收到坠机报告 我测试过的每一款设备,加上谷歌发布前的检查清单,都为这款应用亮起了绿灯。到目前为止,是他们的像素XL 2在启动屏幕时崩溃。我无法获得一个测试。这里是假定崩溃的文件 @Override protected void onCreate(Bundle savedInstanceState) { supe
@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();
}
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
deviceId=Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID);
SharedReferences=GetSharedReferences(“共享位置”,模式多进程);
editor=SharedReferences.edit();
gpsTracker=新的gpsTracker(Splash.this);
locationManager=(locationManager)getSystemService(Context.LOCATION\u服务);
if(android.os.Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS\u FINE\u LOCATION)=授予PackageManager.permission&&ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS\u LOCATION)=授予PackageManager.permission\u){
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,1000,0,此);
getLocationUpdates();
}否则{
ActivityCompat.requestPermissions(Splash.this,新字符串[]{android.Manifest.permission.ACCESS\u FINE\u LOCATION,android.Manifest.permission.ACCESS\u rough\u LOCATION},1);
ActivityCompat.requestPermissions(Splash.this,新字符串[]{android.Manifest.permission.ACCESS\u FINE\u LOCATION},REQUEST\u LOCATION);
}
}否则{
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,1000,0,此);
getLocationUpdates();
token=Utils.getToken(Splash.this,Constant.token);
}
}
Runnable r=新的Runnable(){
@凌驾
公开募捐{
试一试{
睡眠(1000);
}捕获(例外e){
}
ConnectionDetector cd=新的ConnectionDetector(getApplicationContext());
试一试{
布尔值isInternetPresent=cd.isConnectingToInternet();//true或false
如果(isInternetPresent){
RefreshData最近=新的RefreshData();
execute();
}else if(isNetworkAvailable()){
RefreshData最近=新的RefreshData();
execute();
}否则{
普通_类警报(Splash.this);
}
}捕获(例外e){
e、 printStackTrace();
}
}
};
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
开关(请求代码){
//检查最初提供给startResolutionForResult()的整数请求代码。
案例请求检查设置:
开关(结果代码){
案例活动。结果\u正常:
双纬度=gpsTracker.getLatitude();
double longitude=gpsTracker.getLongitude();
strLatitude=字符串.valueOf(纬度);
strlongitute=字符串.valueOf(经度);
editor.putString(“纬度”,String.valueOf(纬度));
editor.putString(“经度”,String.valueOf(经度));
commit();
Intent myIntent=newintent(这个,Splash.class);
myIntent.addFlags(Intent.FLAG\u活动\u无\u动画);
星触觉(myIntent);
完成();
打破
案例活动.RESULT\u已取消:
普通类设置请求(Splash.this);
打破
}
案例PERM\u请求\u代码\u绘制\u覆盖图:
if(requestCode==PERM\u REQUEST\u CODE\u DRAW\u OVERLAYS){
如果(android.os.Build.VERSION.SDK_INT>=23){//android M或以上
如果(!Settings.canDrawOverlays(此)){
//添加用户界面,让用户知道先前未授予系统\u警报\u窗口权限的用户界面。。。
}
}
}
打破
}
}
@凌驾
已更改位置上的公共无效(位置){
}
@凌驾
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
}
public void getLocationUpdates(){
如果(gpsTracker.isGPSEnabled){
双纬度=gpsTracker.getLatitude();
double longitude=gpsTracker.getLongitude();
editor.putString(“纬度”,String.valueOf(纬度));
editor.putString(“经度”,String.valueOf(经度));
commit();
意向服务=新意向(Splash.this、MyService.class);
startService(服务);
螺纹=新螺纹(r);
thread.start();
}否则{
选择警报();
}
}
@凌驾
public void onRequestPermissionsResult(int-requestCode,字符串权限[],int[]grantResults){
开关(请求代码){
案例1:
if(grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION\u已授予){
getLocationUpdates();
token=Utils.getToken(Splash.this,Constant.token);
}
//getLocationUpdates();
打破
}
}
public void selectAlert(){
final AlertDialog.Builder=new AlertDialog.Builder(Splash.this);
builder.setMessage(“Gps已关闭。请选择以下选项之一。”)
setCancela先生
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"/>