简体   繁体   English

Application.onCreate() 未在调试版本中调用

[英]Application.onCreate() not called in debug build

App.onCreate() is not being called at all in debug builds, but called normally in release builds. App.onCreate() 在调试版本中根本没有被调用,而是在发布版本中正常调用。 I expect it to be called each time I press "Run" button of Android Studio.我希望每次按下 Android Studio 的“运行”按钮时都会调用它。 If I put logs in static{} or onCreate(){} they will not appear in log.如果我将日志放在 static{} 或 onCreate(){} 中,它们将不会出现在日志中。 Breakpoints also will not be hit.断点也不会被命中。 Android Strudio version is 3.5.3 with gradle plugin 3.5.3. Android Strudio 版本为 3.5.3,带有 gradle 插件 3.5.3。 This version does not have an "Instant run" feature.此版本没有“即时运行”功能。 Issue also was reproducible in Android Studio 3.5.1.问题也可在 Android Studio 3.5.1 中重现。 I don't understand why it happened, because few days ago everything was working fine.我不明白为什么会这样,因为几天前一切正常。 How to fix this issue?如何解决这个问题? Is it related to the build system or the phone?它与构建系统或手机有关吗?

App class:应用类:

public class App extends Application
{
    static
    {
        System.loadLibrary("some-library-lib");
        // Some logic
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        // Some logic
    }
}

AndroidManifest.xml AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.my_secret.package">

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <!-- Another permissions -->

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".StartupActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Another activities -->

    </application>
</manifest>

I also tried using full-specified App class name in manifest, as:我还尝试在清单中使用完整指定的 App 类名,如:

<application
        android:name="com.my_secret.package.App"

But does not make any difference.但没有任何区别。

The problem disappeared after about two weeks.大约两周后问题就消失了。 I don't know the reason - no changes to the phone or the build system was made.我不知道原因 - 没有对手机或构建系统进行任何更改。
I was working with the release version for a while, and then suddenly installed the debug version, and it started to work fine.我用了一段时间的release版本,然后突然安装了debug版本,它开始正常工作。 I've installed debug versions for all my projects and they were working.我已经为我的所有项目安装了debug版本,并且它们正在运行。
Maybe release/debug interchange has some magic effect, but maybe not.也许release/debug交换有一些神奇的效果,但也许没有。

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

相关问题 Application.onCreate被多次调用 - Application.onCreate called more than once 在Application.onCreate代码之前调用NotificationListenerService - NotificationListenerService called before Application.onCreate code 确定调用Application.onCreate()的进程 - Determine by which process Application.onCreate() is called Android Activity::onCreate 在 Application.onCreate 之前调用 - Android Activity::onCreate called before Application.onCreate 在Application.onCreate()上的BroadcastReceiver - BroadcastReceiver on Application.onCreate() 在BroadcastReceiver.onReceive(..)之前是否会调用Application.onCreate(Bundle)? - Will Application.onCreate(Bundle) be called before BroadcastReceiver.onReceive(..)? 是否有Android注释要求在Application.onCreate期间调用方法? - Is there an Android annotation to require that a method be called during Application.onCreate? 为什么 ContentProvider.onCreate() 在 Application.onCreate() 之前被调用? - Why does ContentProvider.onCreate() get called before Application.onCreate()? 在调试版本中没有调用 onCreate? - onCreate not being called in debug build? 如果应用程序闲置了数小时并被OS破坏,是否在Activity.onResume之前调用Application.onCreate? - Is Application.onCreate called before Activity.onResume if app has been idle for hours and destroyed by OS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM