[英]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.