0

App.onCreate() is not being called at all in debug builds, but called normally in release builds. I expect it to be called each time I press "Run" button of Android Studio. If I put logs in static{} or onCreate(){} they will not appear in log. Breakpoints also will not be hit. Android Strudio version is 3.5.3 with gradle plugin 3.5.3. This version does not have an "Instant run" feature. Issue also was reproducible in 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

<?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:

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

But does not make any difference.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mr. Goldberg
  • 101
  • 9

2 Answers2

0

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. I've installed debug versions for all my projects and they were working.
Maybe release/debug interchange has some magic effect, but maybe not.

Mr. Goldberg
  • 101
  • 9
0

I had similar issue with custom Application class. Especially with Emulators, if you are using emulator wipe cache and start again or just try to use real device. (Incase if you find issues with real device, just restart the device). In my case I just used real device, the debugger just worked fine.

Vijay E
  • 829
  • 10
  • 14