简体   繁体   English

Android 应用程序在 API26 模拟器中崩溃 - 在 API25 和 27 中运行正常

[英]Android app crashes in the API26 emulator - runs ok in API25 and 27

I have been updating my app and have been testing it in Android Studio emulators from API25 to API33.我一直在更新我的应用程序,并在 Android Studio 模拟器中从 API25 到 API33 对其进行了测试。 When I try to run it in an API26 emulator (Android 8.0) the app crashes immediately on launch, with the message "AboutMyJourney has stopped" (The app is called AboutMyJourney)当我尝试在 API26 模拟器 (Android 8.0) 中运行它时,应用程序在启动时立即崩溃,并显示消息“AboutMyJourney 已停止”(该应用程序称为 AboutMyJourney)

I have put a Logcat message at the beginning of the Main (launch) activity:我在主要(启动)活动的开头放置了一条 Logcat 消息:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("sTag","Starting MainActivity");
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_main);
    ......more stuff

and one at the beginning of the activity that gets called next:一个在接下来被调用的活动开始时:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("sTag","Starting AgreeTermsActivity");
    ...more stuff

but it crashes without ever displaying the messages in the Logcat screen.但它在没有在 Logcat 屏幕中显示消息的情况下崩溃了。

I wondered if it could be something to do with the permissions in the Manifest, but I can't figure out what there might be that affects just API26.我想知道这是否与清单中的权限有关,但我无法弄清楚可能仅影响 API26 的内容。 The permissions are:权限是:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" / -->
<uses-permission
    android:name="android.permission.WAKE_LOCK"
    tools:node="replace" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>

However, the app runs without any problem in the API25 and API27 emulators, and the Logcat messages get displayed ok.但是,该应用程序在 API25 和 API27 模拟器中运行没有任何问题,并且 Logcat 消息显示正常。

I have tried deleting and re-installing the SDK platform for API26 and then deleting and re-creating the emulator, but it doesn't solve the problem.我已经尝试删除并重新安装 API26 的 SDK 平台,然后删除并重新创建模拟器,但它并没有解决问题。 The device definition I am using for all the emulators is Nexus 5X.我为所有模拟器使用的设备定义是 Nexus 5X。

One more bit of info: The Event Log shows that the Gradle build was completed and the launch succeeded - no messages after that.还有一点信息:事件日志显示 Gradle 构建已完成并且启动成功 - 之后没有消息。

Can anyone suggest any reasons why I'm getting this problem in API26 and not with other API versions?谁能提出我在 API26 而不是其他 API 版本中遇到此问题的任何原因? Why are the Log messages not showing even though they are right at the start of onCreate?为什么日志消息没有显示,即使它们就在 onCreate 的开始?

(NOTE: I have included the code snippets just to show that the Log messages are at the start of onCreate. The code then goes on to call many other methods, and it just isn't feasible to include all the code here) (注意:我包含代码片段只是为了表明日志消息位于 onCreate 的开头。代码然后继续调用许多其他方法,并且在此处包含所有代码是不可行的)

Thanks for the advice about using the stack trace (I'm still very much a learner!)感谢您提供有关使用堆栈跟踪的建议(我仍然是一个学习者!)

The key piece of information in the stack trace was: ComponentInfo{com.barney.aboutmyjourney/com.barney.aboutmyjourney.MainActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation堆栈跟踪中的关键信息是: ComponentInfo{com.barney.aboutmyjourney/com.barney.aboutmyjourney.MainActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

I removed this: android:screenOrientation="portrait" from the main (launch) activity in the manifest, and it works.我从清单的主要(启动)活动中删除了这个: android:screenOrientation="portrait" ,并且它有效。 To make sure that the main activity uses portrait orientation, I have put some java code in the activity instead.为了确保主要活动使用纵向,我在活动中放置了一些 java 代码。

I don't know why it was failing only with API26, but all is now OK, anyway.我不知道为什么它只在 API26 上失败,但现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Oreo(API26)和android.app.DownloadManager - Android Oreo (API26) and android.app.DownloadManager 在运行Android 7.0(API 24)的模拟器中运行的Android应用在运行Android 4.4(API 19)的手机中崩溃 - Android app that runs in emulator running Android 7.0 (API 24) crashes in phone running Android 4.4 (API 19) 不会显示API26及更高版本中的通知,但会显示较低API中的通知 - Notification in API26 and higher will not be show,but in lower API it will be show minSdk(API25) &gt; deviceSdk(API24) 错误使用 Android Studio 2.2.3 和 Windows 64 PRO 与 OnePlus3 手机 - minSdk(API25) > deviceSdk(API24) error using Android Studio 2.2.3 and Windows 64 PRO with OnePlus3 phone Android Studio 模拟器不适用于 API 27 - Android Studio Emulator not working with API 27 如何以编程方式特别在设备API级别25、26、27上终止来电 - How to end the incoming phone call programmatically specially on devices API level 25,26,27 API 26模拟器上的Android WidgetPreview错误 - Android WidgetPreview Error on API 26 Emulator Android:如果我在具有API 24或25(牛轧糖)的设备上运行该应用程序,则该应用程序将崩溃 - Android: the app crashes if I run it on a device with API 24 or 25 (Nougat) 应用程序在首次运行时崩溃 API 26 - app crashes on first run API 26 API 27不包含带有Google Services的Android模拟器 - Android Emulator with Google Services is not included with API 27
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM